Commit c627d510 by Yvon

rework existing code in select_product_from_bc to simplify, fix a bug and meet…

rework existing code in select_product_from_bc to simplify, fix a bug and meet requirements of story 4820 + do previous qty preselection after user clic on Editer btn
parent de580bd6
Pipeline #2901 failed with stage
in 1 minute 6 seconds
...@@ -93,6 +93,14 @@ function searchUpdatedProduct() { ...@@ -93,6 +93,14 @@ function searchUpdatedProduct() {
// Directly send a line to edition when barcode is read // Directly send a line to edition when barcode is read
function select_product_from_bc(barcode) { function select_product_from_bc(barcode) {
//https://redmine.coopdev.fr/issues/4950
//I have simplified this function by mimicking actions a user would do when it edits or validates a product
//Previously, there were code written here that performed different actions depending on uom,
//I think code implementing such logic should be triggered on btns clicks as well so we don't need it here
//Note also there was a bug in the previous logic (might be consequence of 08/2023 bug fixes in receipt app) :
//in case article was already processed, edit line was opened but product was not removed from processed ones,
//which caused article to be added more than once after a user click on the cross
try { try {
if (editing_product == null) { if (editing_product == null) {
var scannedProduct = barcodes.get_corresponding_odoo_product(barcode); var scannedProduct = barcodes.get_corresponding_odoo_product(barcode);
...@@ -100,66 +108,60 @@ function select_product_from_bc(barcode) { ...@@ -100,66 +108,60 @@ function select_product_from_bc(barcode) {
priceToWeightIsCorrect = true; priceToWeightIsCorrect = true;
if (scannedProduct == null) { if (scannedProduct == null) {
alert("Le code-barre " + barcode + " ne correspond à aucun article connu."); alert(
"Article introuvable.\n" +
return -1; "Le code barre " + barcode + " n'est associé à aucun article." +
" Mettez ce produit de côté et prévenez un salarié.\n" +
"ATTENTION : A la fin de la réception, ne validez pas tant que ce colis n'a pas été ajouté par le salarié.e."
)
return;
} }
var foundProduct = {data: null, place: null}; var product_id = null;
// Does the product come from to_process ? // Does the product come from to_process ?
$.each(list_to_process, function(i, e) { $.each(list_to_process, function(i, e) {
if (e.product_id[0] == scannedProduct.data[barcodes['keys']['id']]) { if (e.product_id[0] == scannedProduct.data[barcodes['keys']['id']]) {
foundProduct.data = e; product_id = e.product_id[0];
foundProduct.place = 'to_process'; return false;
} }
}); });
// Does the product come from processed ? if(product_id !== null) {
if (foundProduct.data == null) { $('#'+product_id+' > td > .toProcess_line_valid').click();
$.each(list_processed, function(i, e) { return;
if (e.product_id[0] == scannedProduct.data[barcodes['keys']['id']]) {
foundProduct.data = JSON.parse(JSON.stringify(e));
foundProduct.data.product_qty = null; // Set qty to null from product already scanned
foundProduct.place = 'processed';
}
});
} }
if (foundProduct.data !== null) { var product_qty = null;
if (foundProduct.data.product_uom[0] == 21) { //if qty is in weight
if (scannedProduct.rule === 'weight') {
editing_product = foundProduct.data;
foundProduct.weightAddition = true; // product weight is directly added
editProductInfo(foundProduct.data, scannedProduct.qty);
editing_product = null;
} else if (scannedProduct.rule === 'price_to_weight') {
openModal($('#templates #modal_confirm_price_to_weight').html(), price_to_weight_is_wrong, 'Non', false, true, price_to_weight_confirmed_callback(foundProduct, scannedProduct));
setupPopUpBtnStyle(scannedProduct);
}
}
if (scannedProduct.rule !== 'price_to_weight') {
if (foundProduct.data.product_uom[0] != 21) {
setLineEdition(foundProduct.data);
}
if (foundProduct.place === 'to_process') {
let row = table_to_process.row($('#'+foundProduct.data.product_id[0]));
remove_from_toProcess(row, foundProduct.data); // Does the product come from processed ?
} $.each(list_processed, function(i, e) {
// Don't remove product from processed list if (e.product_id[0] == scannedProduct.data[barcodes['keys']['id']]) {
product_id = e.product_id[0];
product_qty = e.product_qty;
return false;
} }
});
if(product_id !== null) {
alert("Attention, "+product_qty+" unités de mesure de ce produit ont déjà été comptées.");
$('#'+product_id+' > td > #processed_line_edit').click();
return;
} }
//product found in odoo but it's not in this receipt
alert(
"Article trouvé non concerné par cette réception.\n" +
"Le code barre " + barcode + " n'est associé à aucun article de cette réception." +
" Mettez ce produit de côté et prévenez un salarié.\n" +
"ATTENTION : A la fin de la réception, ne validez pas tant que ce colis n'a pas été ajouté par le salarié.e"
);
} }
} catch (e) { } catch (er) {
err = {msg: e.name + ' : ' + e.message, ctx: 'select_product_from_bc'}; err = {msg: er.name + ' : ' + er.message, ctx: 'select_product_from_bc'};
console.error(err); console.error(err);
report_JS_error(err, 'reception'); report_JS_error(err, 'reception');
} }
return 0;
} }
/** /**
...@@ -374,6 +376,9 @@ function fetch_data(po_ids = null) { ...@@ -374,6 +376,9 @@ function fetch_data(po_ids = null) {
// Load barcodes at page loading, then barcodes are stored locally // Load barcodes at page loading, then barcodes are stored locally
var get_barcodes = async function() { var get_barcodes = async function() {
if (barcodes == null) barcodes = await init_barcodes(); if (barcodes == null) barcodes = await init_barcodes();
//A partial test of https://redmine.coopdev.fr/issues/4950 without scanner : choose barcode and uncomment following line.
//If you paste this line in the console, the focus().select() will not work, but it will work in real conditions
//select_product_from_bc("0493408000008");
}; };
// Get labels to print for current orders from server // Get labels to print for current orders from server
...@@ -874,6 +879,7 @@ function initLists() { ...@@ -874,6 +879,7 @@ function initLists() {
$('table.dataTable').DataTable() $('table.dataTable').DataTable()
.search('') .search('')
.draw(); .draw();
$("#edition_input").focus().select();
} }
} catch (e) { } catch (e) {
err = { err = {
......
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