Commit c72ad4c0 by Félicie

Merge branch '3467-rec-precision-error-adding-products-to-order' into 'dev_cooperatic'

REC: adding products, differenciate unit & kg products for qty precision

See merge request !194
parents 672c5269 eb3c39c8
Pipeline #2315 passed with stage
in 2 minutes 6 seconds
...@@ -277,12 +277,30 @@ tr.odd td.row_product_no_qty { ...@@ -277,12 +277,30 @@ tr.odd td.row_product_no_qty {
} }
.add_product_line_item { .add_product_line_item {
width: 45%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
} }
.input_uom_container {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.product_uom {
margin-left: 10px;
}
.add_product_line .product_name {
width: 60%;
}
.add_product_line .product_qty {
width: 30%;
}
.product_qty_input_alert { .product_qty_input_alert {
color: #d9534f; color: #d9534f;
font-size: 1.4rem; font-size: 1.4rem;
......
...@@ -1979,10 +1979,10 @@ function add_products_action() { ...@@ -1979,10 +1979,10 @@ function add_products_action() {
for (let qty_input of qty_inputs) { for (let qty_input of qty_inputs) {
if ($(qty_input).val() === "") { if ($(qty_input).val() === "") {
has_empty_qty_input = true; has_empty_qty_input = true;
$(qty_input).siblings(".product_qty_input_alert") $(qty_input).closest(".product_qty").find(".product_qty_input_alert")
.show(); .show();
} else { } else {
$(qty_input).siblings(".product_qty_input_alert") $(qty_input).closest(".product_qty").find(".product_qty_input_alert")
.hide(); .hide();
} }
} }
...@@ -2017,16 +2017,23 @@ function create_orders() { ...@@ -2017,16 +2017,23 @@ function create_orders() {
for (let p of products_to_add) { for (let p of products_to_add) {
// Get product qty from input // Get product qty from input
let product_qty = 0; let product_qty = 0;
let product_uom = "";
let add_products_lines = $("#modal .add_product_line"); let add_products_lines = $("#modal .add_product_line");
for (let i = 0; i < add_products_lines.length; i++) { for (let i = 0; i < add_products_lines.length; i++) {
let line = add_products_lines[i]; let line = add_products_lines[i];
if ($(line).find(".product_name") if ($(line).find(".product_name").text() === p.name) {
.text() === p.name) { product_uom = $(line).find(".product_uom").text();
if (product_uom.includes("kg")) {
product_qty = parseFloat($(line).find(".product_qty_input") product_qty = parseFloat($(line).find(".product_qty_input")
.val()); .val());
} else {
product_qty = parseInt($(line).find(".product_qty_input")
.val(), 10);
}
break; break;
} }
} }
...@@ -2034,11 +2041,26 @@ function create_orders() { ...@@ -2034,11 +2041,26 @@ function create_orders() {
let p_supplierinfo = p.suppliersinfo[0]; // product is ordered at its first supplier let p_supplierinfo = p.suppliersinfo[0]; // product is ordered at its first supplier
const supplier_id = p_supplierinfo.supplier_id; const supplier_id = p_supplierinfo.supplier_id;
let item_qty_package = 0;
// If package qty is > than input value, package qty will be used while creating order
let package_qty = p_supplierinfo.package_qty;
if (product_qty < package_qty) {
package_qty = product_qty;
}
// Round differently for unit & kg products
if (product_uom.includes("kg") ) {
item_qty_package = Math.round((product_qty / package_qty) * 1e2) / 1e2;
} else {
item_qty_package = Math.round(product_qty / package_qty)
}
orders_data.suppliers_data[supplier_id].lines.push({ orders_data.suppliers_data[supplier_id].lines.push({
'package_qty': p_supplierinfo.package_qty, 'package_qty': package_qty,
'product_id': p.id, 'product_id': p.id,
'name': p.name, 'name': p.name,
'product_qty_package': (product_qty / p_supplierinfo.package_qty).toFixed(2), 'product_qty_package': item_qty_package,
'product_qty': product_qty, 'product_qty': product_qty,
'product_uom': p.uom_id[0], 'product_uom': p.uom_id[0],
'price_unit': p_supplierinfo.price, 'price_unit': p_supplierinfo.price,
...@@ -2243,6 +2265,7 @@ function set_products_autocomplete() { ...@@ -2243,6 +2265,7 @@ function set_products_autocomplete() {
let add_product_template = $("#add_product_line_template"); let add_product_template = $("#add_product_line_template");
add_product_template.find(".product_name").text(product_name); add_product_template.find(".product_name").text(product_name);
add_product_template.find(".product_uom").text(product.uom_id[1]);
$("#modal .products_lines").append(add_product_template.html()); $("#modal .products_lines").append(add_product_template.html());
if (products_to_add.length === 1) { if (products_to_add.length === 1) {
......
...@@ -219,7 +219,10 @@ ...@@ -219,7 +219,10 @@
<div class="add_product_line"> <div class="add_product_line">
<div class="product_name add_product_line_item"></div> <div class="product_name add_product_line_item"></div>
<div class="product_qty add_product_line_item"> <div class="product_qty add_product_line_item">
<div class="input_uom_container">
<input type="number" autocomplete="off" class="product_qty_input input_small" placeholder="Quantité"> <input type="number" autocomplete="off" class="product_qty_input input_small" placeholder="Quantité">
<div class="product_uom"></div>
</div>
<i class="product_qty_input_alert">Vous devez renseigner une quantité</i> <i class="product_qty_input_alert">Vous devez renseigner une quantité</i>
</div> </div>
<div class="remove_line"> <div class="remove_line">
......
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