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() {
// Directly send a line to edition when barcode is read
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 {
if (editing_product == null) {
var scannedProduct = barcodes.get_corresponding_odoo_product(barcode);
......@@ -100,66 +108,60 @@ function select_product_from_bc(barcode) {
priceToWeightIsCorrect = true;
if (scannedProduct == null) {
alert("Le code-barre " + barcode + " ne correspond à aucun article connu.");
return -1;
alert(
"Article introuvable.\n" +
"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 ?
$.each(list_to_process, function(i, e) {
if (e.product_id[0] == scannedProduct.data[barcodes['keys']['id']]) {
foundProduct.data = e;
foundProduct.place = 'to_process';
product_id = e.product_id[0];
return false;
}
});
if(product_id !== null) {
$('#'+product_id+' > td > .toProcess_line_valid').click();
return;
}
var product_qty = null;
// Does the product come from processed ?
if (foundProduct.data == null) {
$.each(list_processed, function(i, e) {
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';
product_id = e.product_id[0];
product_qty = e.product_qty;
return false;
}
});
}
if (foundProduct.data !== 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(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;
}
if (foundProduct.place === 'to_process') {
let row = table_to_process.row($('#'+foundProduct.data.product_id[0]));
remove_from_toProcess(row, foundProduct.data);
}
// Don't remove product from processed list
}
}
//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) {
err = {msg: e.name + ' : ' + e.message, ctx: 'select_product_from_bc'};
} catch (er) {
err = {msg: er.name + ' : ' + er.message, ctx: 'select_product_from_bc'};
console.error(err);
report_JS_error(err, 'reception');
}
return 0;
}
/**
......@@ -374,6 +376,9 @@ function fetch_data(po_ids = null) {
// Load barcodes at page loading, then barcodes are stored locally
var get_barcodes = async function() {
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
......@@ -874,6 +879,7 @@ function initLists() {
$('table.dataTable').DataTable()
.search('')
.draw();
$("#edition_input").focus().select();
}
} catch (e) {
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