Commit b828ca7e by Alexis AOUN Committed by Alexis Aoun

Correction du bug #1236

parent ad361176
Pipeline #1258 passed with stage
in 1 minute 31 seconds
......@@ -857,6 +857,7 @@ function editProductInfo (productToEdit, value = null, batch = false) {
// Check if the product is already in the 'updated' list
var index = searchUpdatedProduct();
var firstUpdate = false;
var isValid = false;
let newValue = value;
var addition = false;
......@@ -873,10 +874,14 @@ function editProductInfo (productToEdit, value = null, batch = false) {
}
});
// If qty edition & Check if qty changed
if (reception_status == "False" && productToEdit.product_qty != newValue) {
if (index == -1) { // First update
if (reception_status == "False") {
firstUpdate = (index == -1); //first update
if (productToEdit.product_qty != newValue) {
if (firstUpdate) {
productToEdit.old_qty = productToEdit.product_qty;
firstUpdate = true;
} 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
......@@ -887,6 +892,11 @@ function editProductInfo (productToEdit, value = null, batch = false) {
*/
productToEdit.product_qty_package = 1;
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
......@@ -918,6 +928,14 @@ function editProductInfo (productToEdit, value = null, batch = false) {
if (firstUpdate) {
updatedProducts.push(productToEdit);
//if product is validated thru edition -> add to valid_products
if (isValid) {
// 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'] = [];
......@@ -933,6 +951,26 @@ function editProductInfo (productToEdit, value = null, batch = false) {
orders[productToEdit.id_po]['valid_products'].splice(i, 1);
}
}
}
} else {
if (isValid) {
//if product is valid -> remove from updated_products list and add to valid_products list
//removing from updated_products
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']) {
......@@ -942,14 +980,16 @@ function editProductInfo (productToEdit, value = null, batch = false) {
}
}
}
}
if (batch === false) {
// Update product order
update_distant_order(productToEdit.id_po);
}
if(addition){
if (addition) {
let row = table_processed.row($('#'+productToEdit.product_id[0]));
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