Commit 9e213c1d by Yvon

WIP reception : facto + add notion row_counters to keep track of row_counter for…

WIP reception : facto + add notion row_counters to keep track of row_counter for valid products + do not forget row_counter info for updated products
parent db9c1ce2
Pipeline #3241 failed with stage
in 1 minute 4 seconds
...@@ -29,6 +29,7 @@ var reception_status = null, ...@@ -29,6 +29,7 @@ var reception_status = null,
user_comments = "", user_comments = "",
updatedProducts = [], // Keep record of updated products updatedProducts = [], // Keep record of updated products
validProducts = [], // Keep record of directly validated products validProducts = [], // Keep record of directly validated products
rowCounters = {}, // Keep record of row counters of directly validated products
updateType = "", // step 1: qty_valid; step2: br_valid updateType = "", // step 1: qty_valid; step2: br_valid
barcodes = null, // Barcodes stored locally barcodes = null, // Barcodes stored locally
priceToWeightIsCorrect = true, priceToWeightIsCorrect = true,
...@@ -473,7 +474,9 @@ function initLists() { ...@@ -473,7 +474,9 @@ function initLists() {
for (var i = 0; i < updatedProducts.length; i++) { for (var i = 0; i < updatedProducts.length; i++) {
let product = updatedProducts[i]; let product = updatedProducts[i];
if(!('row_counter' in product)) {
product['row_counter'] = -1; product['row_counter'] = -1;
}
list_processed.push(product); list_processed.push(product);
let toProcess_index = list_to_process.findIndex(x => x.id == updatedProducts[i]['id']); let toProcess_index = list_to_process.findIndex(x => x.id == updatedProducts[i]['id']);
...@@ -488,7 +491,13 @@ function initLists() { ...@@ -488,7 +491,13 @@ function initLists() {
if (toProcess_index > -1) { if (toProcess_index > -1) {
let product = list_to_process[toProcess_index]; let product = list_to_process[toProcess_index];
if(!('row_counter' in product)) {
if(validProducts[j] in rowCounters) {
product['row_counter'] = rowCounters[validProducts[j]];
} else {
product['row_counter'] = -1; product['row_counter'] = -1;
}
}
list_processed.push(product); list_processed.push(product);
list_to_process.splice(toProcess_index, 1); list_to_process.splice(toProcess_index, 1);
} }
...@@ -778,10 +787,11 @@ function initLists() { ...@@ -778,10 +787,11 @@ function initLists() {
remove_from_toProcess(row, data); remove_from_toProcess(row, data);
// Update product's order // Update product's order
if (!orders[data.id_po]['valid_products']) { add_to_valid_products(data);
orders[data.id_po]['valid_products'] = [];
} //Remember sort order in which product has been counted
orders[data.id_po]['valid_products'].push(data['id']); add_to_valid_products_row_counters(data);
update_distant_order(data.id_po); update_distant_order(data.id_po);
// Reset search // Reset search
...@@ -1147,13 +1157,9 @@ function set_supplier_shortage(row, product, from_processed = false) { ...@@ -1147,13 +1157,9 @@ function set_supplier_shortage(row, product, from_processed = false) {
orders[product.id_po]['updated_products'].push(product); orders[product.id_po]['updated_products'].push(product);
// ... and remove product from 'direct validated' products if was there // ... and remove product from 'direct validated' products if was there
if ('valid_products' in orders[product.id_po]) { remove_from_valid_products(product);
for (i in orders[product.id_po]['valid_products']) { // ...and clean associated row_counters storage
if (orders[product.id_po]['valid_products'][i] == product['id']) { remove_from_valid_products_row_counters(product);
orders[product.id_po]['valid_products'].splice(i, 1);
}
}
}
} }
} else { } else {
...@@ -1422,10 +1428,8 @@ function editProductInfo (productToEdit, value = null, batch = false) { ...@@ -1422,10 +1428,8 @@ function editProductInfo (productToEdit, value = null, batch = false) {
//if product is validated thru edition without change -> add to valid_products //if product is validated thru edition without change -> add to valid_products
if (isValid) { if (isValid) {
// Create 'valid_products' list in order if not exists // Create 'valid_products' list in order if not exists
if (!orders[productToEdit.id_po]['valid_products']) { add_to_valid_products(productToEdit);
orders[productToEdit.id_po]['valid_products'] = []; add_to_valid_products_row_counters(productToEdit);
}
orders[productToEdit.id_po]['valid_products'].push(productToEdit['id']);
} else { } else {
updatedProducts.push(productToEdit); updatedProducts.push(productToEdit);
...@@ -1439,11 +1443,9 @@ function editProductInfo (productToEdit, value = null, batch = false) { ...@@ -1439,11 +1443,9 @@ function editProductInfo (productToEdit, value = null, batch = false) {
// 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']) { remove_from_valid_products(productToEdit);
if (orders[productToEdit.id_po]['valid_products'][i] == productToEdit['id']) { // ...and clean associated row_counters storage
orders[productToEdit.id_po]['valid_products'].splice(i, 1); remove_from_valid_products_row_counters(productToEdit);
}
}
} }
} else { } else {
if (isValid) { if (isValid) {
...@@ -1460,10 +1462,8 @@ function editProductInfo (productToEdit, value = null, batch = false) { ...@@ -1460,10 +1462,8 @@ function editProductInfo (productToEdit, value = null, batch = false) {
//add to valid_products //add to valid_products
// Create 'valid_products' list in order if not exists // Create 'valid_products' list in order if not exists
if (!orders[productToEdit.id_po]['valid_products']) { add_to_valid_products(productToEdit);
orders[productToEdit.id_po]['valid_products'] = []; add_to_valid_products_row_counters(productToEdit);
}
orders[productToEdit.id_po]['valid_products'].push(productToEdit['id']);
} else { } else {
// Look for product in order's updated products list // Look for product in order's updated products list
...@@ -1910,6 +1910,7 @@ function send(given_products = []) { ...@@ -1910,6 +1910,7 @@ function send(given_products = []) {
// Delete temp data // Delete temp data
delete orders[order_id].valid_products; delete orders[order_id].valid_products;
delete orders[order_id].row_counters;
delete orders[order_id].updated_products; delete orders[order_id].updated_products;
} }
...@@ -2392,6 +2393,41 @@ function set_add_products_modal() { ...@@ -2392,6 +2393,41 @@ function set_add_products_modal() {
} }
} }
function add_to_valid_products(product) {
if (!orders[product.id_po]['valid_products']) {
orders[product.id_po]['valid_products'] = [];
}
orders[product.id_po]['valid_products'].push(product['id']);
}
function add_to_valid_products_row_counters(product) {
if (!orders[product.id_po]['row_counters']) {
orders[product.id_po]['row_counters'] = {};
}
if('row_counter' in product) {
orders[product.id_po]['row_counters'][product['id']] = product['row_counter'];
} else {
orders[product.id_po]['row_counters'][product['id']] = -1;
}
}
function remove_from_valid_products(product) {
if ('valid_products' in orders[product.id_po]) {
for (i in orders[product.id_po]['valid_products']) {
if (orders[product.id_po]['valid_products'][i] == product['id']) {
orders[product.id_po]['valid_products'].splice(i, 1);
}
}
}
}
function remove_from_valid_products_row_counters(product) {
if ('row_counters' in orders[product.id_po]) {
if (product['id'] in orders[product.id_po]['row_counters']) {
orders[product.id_po]['row_counters'].delete(product['id']);
}
}
}
/** /**
* Init the page according to order(s) data (texts, colors, events...) * Init the page according to order(s) data (texts, colors, events...)
...@@ -2753,6 +2789,9 @@ $(document).ready(function() { ...@@ -2753,6 +2789,9 @@ $(document).ready(function() {
if (order["valid_products"]) { if (order["valid_products"]) {
validProducts = validProducts.concat(order["valid_products"]); validProducts = validProducts.concat(order["valid_products"]);
} }
if (order["row_counters"]) {
rowCounters = Object.assign({},rowCounters,order["row_counters"]);
}
// Prepare data to display in 'partner name' area // Prepare data to display in 'partner name' area
partners_display_data.push(`<span class="title_partner_key">${order.key}.</span> ${order.partner} du ${order.date_order}`); partners_display_data.push(`<span class="title_partner_key">${order.key}.</span> ${order.partner} du ${order.date_order}`);
......
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