Commit ccbaf420 by Yvon Kerdoncuff

remove hardcoded uom odoo ids in reception app and be robust to future changes…

remove hardcoded uom odoo ids in reception app and be robust to future changes in uom ids or even names
parent f2dff3c8
Pipeline #4186 failed with stage
in 0 seconds
...@@ -44,6 +44,16 @@ let lastKeypressTime = 0; ...@@ -44,6 +44,16 @@ let lastKeypressTime = 0;
/* UTILS */ /* UTILS */
function is_product_measured_by_unit(product) {
//Be robust to different possible given names
return product.product_uom[1].startsWith('Unit');
}
function is_product_measured_in_kg(product) {
//Be robust to different possible given names
return product.product_uom[1] == 'kg';
}
function back() { function back() {
document.location.href = "/reception"; document.location.href = "/reception";
} }
...@@ -129,7 +139,7 @@ function select_product_from_bc(barcode) { ...@@ -129,7 +139,7 @@ function select_product_from_bc(barcode) {
} }
if (foundProduct.data !== null) { if (foundProduct.data !== null) {
if (foundProduct.data.product_uom[0] == 21) { //if qty is in weight if (is_product_measured_in_kg(foundProduct.data)) { //if qty is in weight
if (scannedProduct.rule === 'weight') { if (scannedProduct.rule === 'weight') {
editing_product = foundProduct.data; editing_product = foundProduct.data;
foundProduct.weightAddition = true; // product weight is directly added foundProduct.weightAddition = true; // product weight is directly added
...@@ -142,7 +152,7 @@ function select_product_from_bc(barcode) { ...@@ -142,7 +152,7 @@ function select_product_from_bc(barcode) {
} }
if (scannedProduct.rule !== 'price_to_weight') { if (scannedProduct.rule !== 'price_to_weight') {
if (foundProduct.data.product_uom[0] != 21) { if (!is_product_measured_in_kg(foundProduct.data)) {
setLineEdition(foundProduct.data); setLineEdition(foundProduct.data);
} }
...@@ -1222,7 +1232,7 @@ function setLineEdition(product) { ...@@ -1222,7 +1232,7 @@ function setLineEdition(product) {
document.getElementById("edition_input").focus(); document.getElementById("edition_input").focus();
// uom // uom
if (editing_product.product_uom[0] == 1) { // Unit if (is_product_measured_by_unit(editing_product)) { // Unit
if (reception_status == 'False' || re_editing_qty === true) { if (reception_status == 'False' || re_editing_qty === true) {
document.getElementById('product_uom').innerHTML = ' unité(s)'; document.getElementById('product_uom').innerHTML = ' unité(s)';
$('#edition_input').attr('type', 'number') $('#edition_input').attr('type', 'number')
...@@ -1234,7 +1244,7 @@ function setLineEdition(product) { ...@@ -1234,7 +1244,7 @@ function setLineEdition(product) {
.attr('step', (allow_four_digits_in_reception_price == "True" ? 0.0001 : 0.01)) .attr('step', (allow_four_digits_in_reception_price == "True" ? 0.0001 : 0.01))
.attr('max', 9999); .attr('max', 9999);
} }
} else if (editing_product.product_uom[0] == 21) { // kg } else if (is_product_measured_in_kg(editing_product)) { // kg
if (reception_status == 'False' || re_editing_qty === true) { if (reception_status == 'False' || re_editing_qty === true) {
document.getElementById('product_uom').innerHTML = ' kg'; document.getElementById('product_uom').innerHTML = ' kg';
$('#edition_input').attr('type', 'number') $('#edition_input').attr('type', 'number')
...@@ -1712,7 +1722,7 @@ function send(given_products = []) { ...@@ -1712,7 +1722,7 @@ function send(given_products = []) {
} }
} }
if (product_copy.product_uom[0] == 21 && products_to_update[i].product_qty > 0.1) { // kg if (is_product_measured_in_kg(product_copy) && products_to_update[i].product_qty > 0.1) { // kg
// Add minimum qty in other orders // Add minimum qty in other orders
product_copy.product_qty_package = 1; product_copy.product_qty_package = 1;
product_copy.package_qty = 0.1; product_copy.package_qty = 0.1;
...@@ -1721,7 +1731,7 @@ function send(given_products = []) { ...@@ -1721,7 +1731,7 @@ function send(given_products = []) {
// Remove this qty from first order // Remove this qty from first order
products_to_update[i].package_qty -= 0.1; products_to_update[i].package_qty -= 0.1;
products_to_update[i].product_qty -= 0.1; products_to_update[i].product_qty -= 0.1;
} else if (product_copy.product_uom[0] == 1 && products_to_update[i].product_qty > 1) { // Unit } else if (is_product_measured_by_unit(product_copy) && products_to_update[i].product_qty > 1) { // Unit
product_copy.product_qty_package = 1; product_copy.product_qty_package = 1;
product_copy.package_qty = 1; product_copy.package_qty = 1;
product_copy.product_qty = 1; product_copy.product_qty = 1;
......
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