Commit 1988c674 by Alexis Aoun

Refactor et renommage de variable

parent da42e4c6
...@@ -68,64 +68,51 @@ function searchUpdatedProduct() { ...@@ -68,64 +68,51 @@ function searchUpdatedProduct() {
function select_product_from_bc(barcode) { function select_product_from_bc(barcode) {
try { try {
if (editing_product == null) { if (editing_product == null) {
var p = barcodes.get_corresponding_odoo_product(barcode); var scannedProduct = barcodes.get_corresponding_odoo_product(barcode);
var qtyIsWeight = false;
var qtyIsPriceToWeight = false;
priceToWeightIsCorrect = true; priceToWeightIsCorrect = true;
console.log(p); if (scannedProduct == null) {
if (p == null) {
alert("Le code-barre " + barcode + " ne correspond à aucun article connu."); alert("Le code-barre " + barcode + " ne correspond à aucun article connu.");
return -1; return -1;
} }
var found = {data: null, place: null}; var foundProduct = {data: null, place: null};
console.log(p.rule);
if(p.rule == 'weight')
qtyIsWeight = true;
else if(p.rule == 'price_to_weight')
qtyIsPriceToWeight = true;
$.each(list_to_process, function(i, e) { $.each(list_to_process, function(i, e) {
if (e.product_id[0] == p.data[barcodes['keys']['id']]) { if (e.product_id[0] == scannedProduct.data[barcodes['keys']['id']]) {
found.data = e; foundProduct.data = e;
found.place = 'to_process'; foundProduct.place = 'to_process';
} }
}); });
if (found.data == null) { if (foundProduct.data == null) {
$.each(list_processed, function(i, e) { $.each(list_processed, function(i, e) {
if (e.product_id[0] == p.data[barcodes['keys']['id']]) { if (e.product_id[0] == scannedProduct.data[barcodes['keys']['id']]) {
found.data = JSON.parse(JSON.stringify(e)); foundProduct.data = JSON.parse(JSON.stringify(e));
found.place = 'processed'; foundProduct.place = 'processed';
} }
}); });
} }
if(qtyIsWeight) if(scannedProduct.rule == 'weight')
found.data.product_qty = p.qty; foundProduct.data.product_qty = scannedProduct.qty;
else if(qtyIsPriceToWeight){ 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(found, p)); openModal($('#templates #modal_confirm_price_to_weight').html(), price_to_weight_is_wrong, 'Non', false, true, price_to_weight_confirmed_callback(foundProduct, scannedProduct));
setupPopUpBtnStyle(p); setupPopUpBtnStyle(scannedProduct);
} }
if(found.data !== null && !qtyIsPriceToWeight){ if(foundProduct.data !== null && !(scannedProduct.rule == 'price_to_weight')){
if(qtyIsWeight) if(scannedProduct.rule == 'weight')
editProductInfo(found.data, found.data.product_qty); editProductInfo(foundProduct.data, foundProduct.data.product_qty);
else else
setLineEdition(found.data); setLineEdition(foundProduct.data);
if (found.place === 'to_process') {
let row = table_to_process.row($('#'+found.data.product_id[0]));
remove_from_toProcess(row, found.data); if (foundProduct.place === 'to_process') {
let row = table_to_process.row($('#'+foundProduct.data.product_id[0]));
remove_from_toProcess(row, foundProduct.data);
} }
} }
} }
......
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