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,
user_comments = "",
updatedProducts = [], // Keep record of updated 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
barcodes = null, // Barcodes stored locally
priceToWeightIsCorrect = true,
......@@ -473,7 +474,9 @@ function initLists() {
for (var i = 0; i < updatedProducts.length; i++) {
let product = updatedProducts[i];
if(!('row_counter' in product)) {
product['row_counter'] = -1;
}
list_processed.push(product);
let toProcess_index = list_to_process.findIndex(x => x.id == updatedProducts[i]['id']);
......@@ -488,7 +491,13 @@ function initLists() {
if (toProcess_index > -1) {
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;
}
}
list_processed.push(product);
list_to_process.splice(toProcess_index, 1);
}
......@@ -778,10 +787,11 @@ function initLists() {
remove_from_toProcess(row, data);
// Update product's order
if (!orders[data.id_po]['valid_products']) {
orders[data.id_po]['valid_products'] = [];
}
orders[data.id_po]['valid_products'].push(data['id']);
add_to_valid_products(data);
//Remember sort order in which product has been counted
add_to_valid_products_row_counters(data);
update_distant_order(data.id_po);
// Reset search
......@@ -1147,13 +1157,9 @@ function set_supplier_shortage(row, product, from_processed = false) {
orders[product.id_po]['updated_products'].push(product);
// ... and remove product from 'direct validated' products if was there
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);
}
}
}
remove_from_valid_products(product);
// ...and clean associated row_counters storage
remove_from_valid_products_row_counters(product);
}
} else {
......@@ -1422,10 +1428,8 @@ function editProductInfo (productToEdit, value = null, batch = false) {
//if product is validated thru edition without change -> 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']);
add_to_valid_products(productToEdit);
add_to_valid_products_row_counters(productToEdit);
} else {
updatedProducts.push(productToEdit);
......@@ -1439,11 +1443,9 @@ function editProductInfo (productToEdit, value = null, batch = false) {
// May have been directly validated then updated from processed list
// -> remove from 'valid_products' list
for (i in orders[productToEdit.id_po]['valid_products']) {
if (orders[productToEdit.id_po]['valid_products'][i] == productToEdit['id']) {
orders[productToEdit.id_po]['valid_products'].splice(i, 1);
}
}
remove_from_valid_products(productToEdit);
// ...and clean associated row_counters storage
remove_from_valid_products_row_counters(productToEdit);
}
} else {
if (isValid) {
......@@ -1460,10 +1462,8 @@ function editProductInfo (productToEdit, value = null, batch = false) {
//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']);
add_to_valid_products(productToEdit);
add_to_valid_products_row_counters(productToEdit);
} else {
// Look for product in order's updated products list
......@@ -1910,6 +1910,7 @@ function send(given_products = []) {
// Delete temp data
delete orders[order_id].valid_products;
delete orders[order_id].row_counters;
delete orders[order_id].updated_products;
}
......@@ -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...)
......@@ -2753,6 +2789,9 @@ $(document).ready(function() {
if (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
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