Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
third-party
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cooperatic-foodcoops
third-party
Commits
d15becc6
Commit
d15becc6
authored
May 28, 2021
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
linting
parent
7b60a5d4
Pipeline
#988
passed with stage
in 22 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
45 deletions
+66
-45
orders_helper.js
orders/static/js/orders_helper.js
+66
-45
No files found.
orders/static/js/orders_helper.js
View file @
d15becc6
var
suppliers_list
=
[],
var
suppliers_list
=
[],
products_table
=
null
,
products_table
=
null
,
products
=
[]
products
=
[]
,
selected_suppliers
=
[],
selected_suppliers
=
[],
selected_rows
=
[];
selected_rows
=
[];
...
@@ -94,13 +94,13 @@ function remove_supplier(supplier_id) {
...
@@ -94,13 +94,13 @@ function remove_supplier(supplier_id) {
* @param {object} supplier
* @param {object} supplier
* @param {node} cell product's row in datatable
* @param {node} cell product's row in datatable
*/
*/
function
save_supplier_product_association
(
product
,
supplier
,
cell
)
{
function
save_supplier_product_association
(
product
,
supplier
,
cell
)
{
openModal
();
openModal
();
const
data
=
{
const
data
=
{
product_tmpl_id
:
product
.
id
,
product_tmpl_id
:
product
.
id
,
supplier_id
:
supplier
.
id
supplier_id
:
supplier
.
id
}
}
;
// Fetch supplier products
// Fetch supplier products
$
.
ajax
({
$
.
ajax
({
...
@@ -112,19 +112,22 @@ function remove_supplier(supplier_id) {
...
@@ -112,19 +112,22 @@ function remove_supplier(supplier_id) {
data
:
JSON
.
stringify
(
data
),
data
:
JSON
.
stringify
(
data
),
success
:
()
=>
{
success
:
()
=>
{
// Save relation locally
// Save relation locally
save_supplier_products
(
supplier
,
[
product
])
save_supplier_products
(
supplier
,
[
product
])
;
// Update table
// Update table
$
(
cell
).
removeClass
(
"product_not_from_supplier"
)
$
(
cell
).
removeClass
(
"product_not_from_supplier"
);
const
row
=
$
(
cell
).
closest
(
"tr"
)
const
row
=
$
(
cell
).
closest
(
"tr"
);
const
new_row_data
=
prepare_datatable_data
([
product
.
id
])[
0
]
const
new_row_data
=
prepare_datatable_data
([
product
.
id
])[
0
];
products_table
.
row
(
row
).
data
(
new_row_data
).
draw
()
products_table
.
row
(
row
).
data
(
new_row_data
)
.
draw
();
closeModal
();
closeModal
();
},
},
error
:
function
(
data
)
{
error
:
function
(
data
)
{
let
msg
=
"erreur serveur lors de la sauvegarde de l'association product/supplier"
.
let
msg
=
"erreur serveur lors de la sauvegarde de l'association product/supplier"
.
msg
+=
` (product_tmpl_id:
${
product
.
id
}
; supplier_id:
${
supplier
.
id
}
)`
msg
+=
` (product_tmpl_id:
${
product
.
id
}
; supplier_id:
${
supplier
.
id
}
)`
;
err
=
{
msg
:
msg
,
ctx
:
'save_supplier_product_association'
};
err
=
{
msg
:
msg
,
ctx
:
'save_supplier_product_association'
};
if
(
typeof
data
.
responseJSON
!=
'undefined'
&&
typeof
data
.
responseJSON
.
error
!=
'undefined'
)
{
if
(
typeof
data
.
responseJSON
!=
'undefined'
&&
typeof
data
.
responseJSON
.
error
!=
'undefined'
)
{
err
.
msg
+=
' : '
+
data
.
responseJSON
.
error
;
err
.
msg
+=
' : '
+
data
.
responseJSON
.
error
;
...
@@ -220,6 +223,7 @@ function display_suppliers() {
...
@@ -220,6 +223,7 @@ function display_suppliers() {
const
supplier_id
=
el_id
[
el_id
.
length
-
1
];
const
supplier_id
=
el_id
[
el_id
.
length
-
1
];
let
modal_remove_supplier
=
$
(
'#templates #modal_remove_supplier'
);
let
modal_remove_supplier
=
$
(
'#templates #modal_remove_supplier'
);
modal_remove_supplier
.
find
(
".supplier_name"
).
text
(
supplier
.
display_name
);
modal_remove_supplier
.
find
(
".supplier_name"
).
text
(
supplier
.
display_name
);
openModal
(
openModal
(
...
@@ -240,7 +244,7 @@ function display_suppliers() {
...
@@ -240,7 +244,7 @@ function display_suppliers() {
*/
*/
function
prepare_datatable_data
(
product_ids
=
[])
{
function
prepare_datatable_data
(
product_ids
=
[])
{
let
data
=
[];
let
data
=
[];
let
products_to_format
=
[]
let
products_to_format
=
[]
;
if
(
product_ids
.
length
>
0
)
{
if
(
product_ids
.
length
>
0
)
{
products_to_format
=
products
.
filter
(
p
=>
product_ids
.
includes
(
p
.
id
));
products_to_format
=
products
.
filter
(
p
=>
product_ids
.
includes
(
p
.
id
));
...
@@ -255,7 +259,7 @@ function prepare_datatable_data(product_ids = []) {
...
@@ -255,7 +259,7 @@ function prepare_datatable_data(product_ids = []) {
default_code
:
product
.
default_code
,
default_code
:
product
.
default_code
,
incoming_qty
:
+
parseFloat
(
product
.
incoming_qty
).
toFixed
(
3
),
// + sign removes unecessary zeroes at the end
incoming_qty
:
+
parseFloat
(
product
.
incoming_qty
).
toFixed
(
3
),
// + sign removes unecessary zeroes at the end
qty_available
:
+
parseFloat
(
product
.
qty_available
).
toFixed
(
3
),
qty_available
:
+
parseFloat
(
product
.
qty_available
).
toFixed
(
3
),
uom
:
product
.
uom_id
[
1
]
,
uom
:
product
.
uom_id
[
1
]
};
};
// If product not related to supplier : false ; else null (qty to be set) or qty
// If product not related to supplier : false ; else null (qty to be set) or qty
...
@@ -282,7 +286,6 @@ function prepare_datatable_columns() {
...
@@ -282,7 +286,6 @@ function prepare_datatable_columns() {
columns
=
[
columns
=
[
{
{
data
:
"id"
,
data
:
"id"
,
title
:
"id"
,
title
:
` <div id="table_header_select_all">
title
:
` <div id="table_header_select_all">
Tout
Tout
<input type="checkbox" class="select_product_cb" id="select_all_products_cb" value="all">
<input type="checkbox" class="select_product_cb" id="select_all_products_cb" value="all">
...
@@ -292,7 +295,7 @@ function prepare_datatable_columns() {
...
@@ -292,7 +295,7 @@ function prepare_datatable_columns() {
render
:
function
(
data
)
{
render
:
function
(
data
)
{
return
`<input type="checkbox" class="select_product_cb" id="select_product_
${
data
}
" value="
${
data
}
">`
;
return
`<input type="checkbox" class="select_product_cb" id="select_product_
${
data
}
" value="
${
data
}
">`
;
},
},
width
:
"4%"
,
width
:
"4%"
},
},
{
{
data
:
"default_code"
,
data
:
"default_code"
,
...
@@ -309,13 +312,13 @@ function prepare_datatable_columns() {
...
@@ -309,13 +312,13 @@ function prepare_datatable_columns() {
{
{
data
:
"qty_available"
,
data
:
"qty_available"
,
title
:
"Stock"
,
title
:
"Stock"
,
width
:
"5%"
,
width
:
"5%"
},
},
{
{
data
:
"incoming_qty"
,
data
:
"incoming_qty"
,
title
:
"Quantité entrante"
,
title
:
"Quantité entrante"
,
width
:
"5%"
,
width
:
"5%"
}
,
}
];
];
for
(
const
supplier
of
selected_suppliers
)
{
for
(
const
supplier
of
selected_suppliers
)
{
...
@@ -341,8 +344,8 @@ function prepare_datatable_columns() {
...
@@ -341,8 +344,8 @@ function prepare_datatable_columns() {
columns
.
push
({
columns
.
push
({
data
:
"uom"
,
data
:
"uom"
,
title
:
"UDM"
,
title
:
"UDM"
,
width
:
"5%"
,
width
:
"5%"
})
})
;
return
columns
;
return
columns
;
}
}
...
@@ -379,13 +382,13 @@ function display_products() {
...
@@ -379,13 +382,13 @@ function display_products() {
orderClasses
:
false
,
orderClasses
:
false
,
iDisplayLength
:
100
,
iDisplayLength
:
100
,
language
:
{
url
:
'/static/js/datatables/french.json'
},
language
:
{
url
:
'/static/js/datatables/french.json'
},
createdRow
:
function
(
row
,
data
,
dataIndex
)
{
createdRow
:
function
(
row
)
{
for
(
const
cell_node
of
row
.
cells
)
{
for
(
const
cell_node
of
row
.
cells
)
{
const
cell
=
$
(
cell_node
);
const
cell
=
$
(
cell_node
);
if
(
cell
.
hasClass
(
"supplier_input_cell"
))
{
if
(
cell
.
hasClass
(
"supplier_input_cell"
))
{
if
(
cell
.
text
()
==
"X"
)
{
if
(
cell
.
text
()
==
"X"
)
{
cell
.
addClass
(
'product_not_from_supplier'
);
cell
.
addClass
(
'product_not_from_supplier'
);
}
else
{
}
else
{
// TODO: supplier shortage cell coloring, when supplier shortage usecase is defined
// TODO: supplier shortage cell coloring, when supplier shortage usecase is defined
...
@@ -419,24 +422,25 @@ function display_products() {
...
@@ -419,24 +422,25 @@ function display_products() {
// Associate product to supplier on click on 'X' in the table
// Associate product to supplier on click on 'X' in the table
$
(
'#products_table'
).
on
(
'click'
,
'tbody .product_not_from_supplier'
,
function
()
{
$
(
'#products_table'
).
on
(
'click'
,
'tbody .product_not_from_supplier'
,
function
()
{
// Get supplier & product id
// Get supplier & product id
const
el_id
=
$
(
this
).
children
().
first
().
attr
(
'id'
)
const
el_id
=
$
(
this
).
children
()
.
first
()
.
attr
(
'id'
)
.
split
(
'_'
);
.
split
(
'_'
);
const
product_id
=
el_id
[
1
];
const
product_id
=
el_id
[
1
];
const
supplier_id
=
el_id
[
3
];
const
supplier_id
=
el_id
[
3
];
const
product
=
products
.
find
(
p
=>
p
.
id
==
product_id
)
const
product
=
products
.
find
(
p
=>
p
.
id
==
product_id
)
;
const
supplier
=
selected_suppliers
.
find
(
s
=>
s
.
id
==
supplier_id
)
const
supplier
=
selected_suppliers
.
find
(
s
=>
s
.
id
==
supplier_id
)
;
let
modal_attach_product_to_supplier
=
$
(
'#templates #modal_attach_product_to_supplier'
);
let
modal_attach_product_to_supplier
=
$
(
'#templates #modal_attach_product_to_supplier'
);
modal_attach_product_to_supplier
.
find
(
".product_name"
).
text
(
product
.
name
);
modal_attach_product_to_supplier
.
find
(
".product_name"
).
text
(
product
.
name
);
modal_attach_product_to_supplier
.
find
(
".supplier_name"
).
text
(
supplier
.
display_name
);
modal_attach_product_to_supplier
.
find
(
".supplier_name"
).
text
(
supplier
.
display_name
);
const
cell
=
this
openModal
(
openModal
(
modal_attach_product_to_supplier
.
html
(),
modal_attach_product_to_supplier
.
html
(),
()
=>
{
()
=>
{
save_supplier_product_association
(
product
,
supplier
,
cell
);
save_supplier_product_association
(
product
,
supplier
,
this
);
},
},
'Valider'
,
'Valider'
,
false
false
...
@@ -446,29 +450,35 @@ function display_products() {
...
@@ -446,29 +450,35 @@ function display_products() {
// Select row(s) on checkbox change
// Select row(s) on checkbox change
$
(
'#products_table'
).
on
(
'click'
,
'thead th #select_all_products_cb'
,
function
()
{
$
(
'#products_table'
).
on
(
'click'
,
'thead th #select_all_products_cb'
,
function
()
{
if
(
this
.
checked
)
{
if
(
this
.
checked
)
{
selected_rows
=
[]
selected_rows
=
[]
;
products_table
.
rows
().
every
(
function
()
{
products_table
.
rows
().
every
(
function
()
{
const
node
=
$
(
this
.
node
());
const
node
=
$
(
this
.
node
());
node
.
addClass
(
'selected'
);
node
.
addClass
(
'selected'
);
node
.
find
(
".select_product_cb"
).
first
().
prop
(
"checked"
,
true
);
node
.
find
(
".select_product_cb"
).
first
()
.
prop
(
"checked"
,
true
);
// Save selected rows in case the table is updated
// Save selected rows in case the table is updated
selected_rows
.
push
(
this
.
data
().
id
)
selected_rows
.
push
(
this
.
data
().
id
);
return
0
;
});
});
}
else
{
}
else
{
unselect_all_rows
()
unselect_all_rows
()
;
}
}
});
});
$
(
'#products_table'
).
on
(
'click'
,
'tbody td .select_product_cb'
,
function
()
{
$
(
'#products_table'
).
on
(
'click'
,
'tbody td .select_product_cb'
,
function
()
{
$
(
this
).
closest
(
'tr'
).
toggleClass
(
'selected'
);
$
(
this
).
closest
(
'tr'
)
.
toggleClass
(
'selected'
);
// Save / unsave selected row
// Save / unsave selected row
p_id
=
products_table
.
row
(
$
(
this
).
closest
(
'tr'
)).
data
().
id
;
p_id
=
products_table
.
row
(
$
(
this
).
closest
(
'tr'
)).
data
().
id
;
if
(
this
.
checked
)
{
if
(
this
.
checked
)
{
selected_rows
.
push
(
p_id
)
selected_rows
.
push
(
p_id
)
;
}
else
{
}
else
{
const
i
=
selected_rows
.
findIndex
(
id
=>
id
==
p_id
)
const
i
=
selected_rows
.
findIndex
(
id
=>
id
==
p_id
);
selected_rows
.
splice
(
i
,
1
)
selected_rows
.
splice
(
i
,
1
);
}
}
});
});
...
@@ -481,11 +491,15 @@ function display_products() {
...
@@ -481,11 +491,15 @@ function display_products() {
function
unselect_all_rows
()
{
function
unselect_all_rows
()
{
products_table
.
rows
().
every
(
function
()
{
products_table
.
rows
().
every
(
function
()
{
const
node
=
$
(
this
.
node
());
const
node
=
$
(
this
.
node
());
node
.
removeClass
(
'selected'
);
node
.
removeClass
(
'selected'
);
node
.
find
(
".select_product_cb"
).
first
().
prop
(
"checked"
,
false
);
node
.
find
(
".select_product_cb"
).
first
()
.
prop
(
"checked"
,
false
);
return
0
;
});
});
selected_rows
=
[]
selected_rows
=
[]
;
}
}
/**
/**
...
@@ -501,13 +515,17 @@ function update_display() {
...
@@ -501,13 +515,17 @@ function update_display() {
display_products
();
display_products
();
// Re-select previously selected rows
// Re-select previously selected rows
if
(
selected_rows
.
length
>
0
)
{
if
(
selected_rows
.
length
>
0
)
{
products_table
.
rows
().
every
(
function
()
{
products_table
.
rows
().
every
(
function
()
{
if
(
selected_rows
.
includes
(
this
.
data
().
id
))
{
if
(
selected_rows
.
includes
(
this
.
data
().
id
))
{
const
node
=
$
(
this
.
node
());
const
node
=
$
(
this
.
node
());
node
.
addClass
(
'selected'
);
node
.
addClass
(
'selected'
);
node
.
find
(
".select_product_cb"
).
first
().
prop
(
"checked"
,
true
);
node
.
find
(
".select_product_cb"
).
first
()
.
prop
(
"checked"
,
true
);
}
}
return
0
;
});
});
}
}
}
}
...
@@ -517,25 +535,27 @@ function generate_inventory() {
...
@@ -517,25 +535,27 @@ function generate_inventory() {
const
selected_data
=
products_table
.
rows
(
'.selected'
).
data
();
const
selected_data
=
products_table
.
rows
(
'.selected'
).
data
();
if
(
selected_data
.
length
==
0
)
{
if
(
selected_data
.
length
==
0
)
{
alert
(
"Veuillez sélectionner les produits à inventorier en cochant les cases sur la gauche du tableau."
)
alert
(
"Veuillez sélectionner les produits à inventorier en cochant les cases sur la gauche du tableau."
)
;
}
else
{
}
else
{
data
=
{
data
=
{
lines
:
[],
lines
:
[],
partners_id
:
[],
partners_id
:
[],
type
:
'product_templates'
type
:
'product_templates'
}
}
;
for
(
var
i
=
0
;
i
<
selected_data
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
selected_data
.
length
;
i
++
)
{
const
product
=
products
.
find
(
p
=>
p
.
id
==
selected_data
[
i
].
id
)
const
product
=
products
.
find
(
p
=>
p
.
id
==
selected_data
[
i
].
id
);
data
.
lines
.
push
(
product
.
id
);
data
.
lines
.
push
(
product
.
id
);
for
(
const
supplier
of
product
.
suppliers
)
{
for
(
const
supplier
of
product
.
suppliers
)
{
if
(
data
.
partners_id
.
indexOf
(
supplier
.
id
)
===
-
1
)
{
if
(
data
.
partners_id
.
indexOf
(
supplier
.
id
)
===
-
1
)
{
data
.
partners_id
.
push
(
supplier
.
id
)
data
.
partners_id
.
push
(
supplier
.
id
)
;
}
}
}
}
}
}
let
modal_create_inventory
=
$
(
'#templates #modal_create_inventory'
);
let
modal_create_inventory
=
$
(
'#templates #modal_create_inventory'
);
modal_create_inventory
.
find
(
".inventory_products_count"
).
text
(
data
.
lines
.
length
);
modal_create_inventory
.
find
(
".inventory_products_count"
).
text
(
data
.
lines
.
length
);
openModal
(
openModal
(
...
@@ -552,7 +572,7 @@ function generate_inventory() {
...
@@ -552,7 +572,7 @@ function generate_inventory() {
unselect_all_rows
();
unselect_all_rows
();
// Give time for modal to fade
// Give time for modal to fade
setTimeout
(
function
()
{
setTimeout
(
function
()
{
$
.
notify
(
$
.
notify
(
"Inventaire créé !"
,
"Inventaire créé !"
,
{
{
...
@@ -565,6 +585,7 @@ function generate_inventory() {
...
@@ -565,6 +585,7 @@ function generate_inventory() {
error
:
function
(
data
)
{
error
:
function
(
data
)
{
let
msg
=
"erreur serveur lors de la création de l'inventaire"
.
let
msg
=
"erreur serveur lors de la création de l'inventaire"
.
err
=
{
msg
:
msg
,
ctx
:
'generate_inventory'
};
err
=
{
msg
:
msg
,
ctx
:
'generate_inventory'
};
if
(
typeof
data
.
responseJSON
!=
'undefined'
&&
typeof
data
.
responseJSON
.
error
!=
'undefined'
)
{
if
(
typeof
data
.
responseJSON
!=
'undefined'
&&
typeof
data
.
responseJSON
.
error
!=
'undefined'
)
{
err
.
msg
+=
' : '
+
data
.
responseJSON
.
error
;
err
.
msg
+=
' : '
+
data
.
responseJSON
.
error
;
}
}
...
@@ -574,7 +595,7 @@ function generate_inventory() {
...
@@ -574,7 +595,7 @@ function generate_inventory() {
}
}
});
});
},
},
'Valider'
,
'Valider'
);
);
}
}
}
}
...
@@ -619,7 +640,7 @@ $(document).ready(function() {
...
@@ -619,7 +640,7 @@ $(document).ready(function() {
add_supplier
();
add_supplier
();
});
});
$
(
"#do_inventory"
).
on
(
"click"
,
function
(
e
)
{
$
(
"#do_inventory"
).
on
(
"click"
,
function
()
{
generate_inventory
();
generate_inventory
();
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment