Commit e29b2ce7 by François C.

Merge branch 'fix_bug-1236' into 'dev_principale'

Correction du bug #1236

See merge request cooperatic-foodcoops/third-party!52
parents b84d97e8 b828ca7e
Pipeline #1274 passed with stage
in 1 minute 22 seconds
...@@ -857,6 +857,7 @@ function editProductInfo (productToEdit, value = null, batch = false) { ...@@ -857,6 +857,7 @@ function editProductInfo (productToEdit, value = null, batch = false) {
// Check if the product is already in the 'updated' list // Check if the product is already in the 'updated' list
var index = searchUpdatedProduct(); var index = searchUpdatedProduct();
var firstUpdate = false; var firstUpdate = false;
var isValid = false;
let newValue = value; let newValue = value;
var addition = false; var addition = false;
...@@ -873,20 +874,29 @@ function editProductInfo (productToEdit, value = null, batch = false) { ...@@ -873,20 +874,29 @@ function editProductInfo (productToEdit, value = null, batch = false) {
} }
}); });
// If qty edition & Check if qty changed // If qty edition & Check if qty changed
if (reception_status == "False" && productToEdit.product_qty != newValue) { if (reception_status == "False") {
if (index == -1) { // First update firstUpdate = (index == -1); //first update
productToEdit.old_qty = productToEdit.product_qty; if (productToEdit.product_qty != newValue) {
firstUpdate = true; if (firstUpdate) {
} productToEdit.old_qty = productToEdit.product_qty;
} else {
//if it is not the first update AND newValue is equal to the validation qty then the product is valid
isValid = (newValue === productToEdit.old_qty);
}
// Edit product info // Edit product info
productToEdit.product_qty = newValue; productToEdit.product_qty = newValue;
/* /*
If qty has changed, we choose to set detailed values as follow: If qty has changed, we choose to set detailed values as follow:
1 package (product_qty_package) of X products (package_qty) 1 package (product_qty_package) of X products (package_qty)
*/ */
productToEdit.product_qty_package = 1; productToEdit.product_qty_package = 1;
productToEdit.package_qty = productToEdit.product_qty; productToEdit.package_qty = productToEdit.product_qty;
} else if (firstUpdate) {
// if the product is updated for the first time and productQty is equal to the newValue then the product is validated
isValid = true;
}
} }
// Check if price changed // Check if price changed
...@@ -918,27 +928,56 @@ function editProductInfo (productToEdit, value = null, batch = false) { ...@@ -918,27 +928,56 @@ function editProductInfo (productToEdit, value = null, batch = false) {
if (firstUpdate) { if (firstUpdate) {
updatedProducts.push(productToEdit); updatedProducts.push(productToEdit);
// Create 'updated_products' list in order if not exists //if product is validated thru edition -> add to valid_products
if (!orders[productToEdit.id_po]['updated_products']) { if (isValid) {
orders[productToEdit.id_po]['updated_products'] = []; // Create 'valid_products' list in order if not exists
} if (!orders[productToEdit.id_po]['valid_products']) {
orders[productToEdit.id_po]['valid_products'] = [];
}
orders[productToEdit.id_po]['valid_products'].push(productToEdit['id']);
} else {
// Create 'updated_products' list in order if not exists
if (!orders[productToEdit.id_po]['updated_products']) {
orders[productToEdit.id_po]['updated_products'] = [];
}
// Add product to order's updated products if first update // Add product to order's updated products if first update
orders[productToEdit.id_po]['updated_products'].push(productToEdit); orders[productToEdit.id_po]['updated_products'].push(productToEdit);
// May have been directly validated then updated from processed list // May have been directly validated then updated from processed list
// -> remove from 'valid_products' list // -> remove from 'valid_products' list
for (i in orders[productToEdit.id_po]['valid_products']) { for (i in orders[productToEdit.id_po]['valid_products']) {
if (orders[productToEdit.id_po]['valid_products'][i] == productToEdit['id']) { if (orders[productToEdit.id_po]['valid_products'][i] == productToEdit['id']) {
orders[productToEdit.id_po]['valid_products'].splice(i, 1); orders[productToEdit.id_po]['valid_products'].splice(i, 1);
}
} }
} }
} else { } else {
// Look for product in order's updated products list
for (i in orders[productToEdit.id_po]['updated_products']) { if (isValid) {
if (orders[productToEdit.id_po]['updated_products'][i]['product_id'][0] //if product is valid -> remove from updated_products list and add to valid_products list
== productToEdit['product_id'][0]) { //removing from updated_products
orders[productToEdit.id_po]['updated_products'][i] = productToEdit; for (i in orders[productToEdit.id_po]['updated_products']) {
if (orders[productToEdit.id_po]['updated_products'][i]['product_id'][0]
== productToEdit['product_id'][0]) {
orders[productToEdit.id_po]['updated_products'].splice(i, 1);
}
}
//add to valid_products
// Create 'valid_products' list in order if not exists
if (!orders[productToEdit.id_po]['valid_products']) {
orders[productToEdit.id_po]['valid_products'] = [];
}
orders[productToEdit.id_po]['valid_products'].push(productToEdit['id']);
} else {
// Look for product in order's updated products list
for (i in orders[productToEdit.id_po]['updated_products']) {
if (orders[productToEdit.id_po]['updated_products'][i]['product_id'][0]
== productToEdit['product_id'][0]) {
orders[productToEdit.id_po]['updated_products'][i] = productToEdit;
}
} }
} }
} }
...@@ -948,8 +987,9 @@ function editProductInfo (productToEdit, value = null, batch = false) { ...@@ -948,8 +987,9 @@ function editProductInfo (productToEdit, value = null, batch = false) {
update_distant_order(productToEdit.id_po); update_distant_order(productToEdit.id_po);
} }
if(addition){ if (addition) {
let row = table_processed.row($('#'+productToEdit.product_id[0])); let row = table_processed.row($('#'+productToEdit.product_id[0]));
remove_from_processed(row, productToEdit); remove_from_processed(row, productToEdit);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment