Commit 7c90768f by François C.

Merge branch 'ticket_608' into 'dev_cooperatic'

ticket_608 resolut : 	modifié :         stock/static/js/stock_movements.js

See merge request !46
parents bc0bdfc8 980bfca4
Pipeline #1202 passed with stage
in 1 minute 24 seconds
...@@ -162,34 +162,15 @@ function init_datatable() { ...@@ -162,34 +162,15 @@ function init_datatable() {
// Listener on inputs // Listener on inputs
$('#products_table tbody').on('change', '.stock_edit_input', function () { $('#products_table tbody').on('change', '.stock_edit_input', function () {
let qty = $(this).val(); let qty = $(this).val();
let row = products_table.row($(this).parents('tr')); let row = products_table.row($(this).parents('tr'));
let data = row.data(); let data = row.data();
let validated_data = qty_validation(qty, data.uom.id); let validated_data = qty_validation(qty, data.uom.id);
if (validated_data >= 0) { if (validated_data >= 0) {
data.qty = validated_data; data.qty = validated_data;
row.remove().draw(); row.remove().draw();
products_table.row.add(data).draw(); products_table.row.add(data).draw();
} else {
data.qty = null;
row.remove().draw();
products_table.row.add(data).draw();
if (validated_data == -2) {
$.notify("Ce produit est vendu à l'unité : la valeur doit être un nombre entier !", {
globalPosition:"top right",
className: "error"
});
} else if (validated_data == -1 || validated_data == -3) {
$.notify("Valeur invalide.", {
globalPosition:"top right",
className: "error"
});
}
} }
update_total_value(); update_total_value();
}); });
...@@ -441,20 +422,29 @@ var update_existing_product = function(product, added_qty, undo_option = false) ...@@ -441,20 +422,29 @@ var update_existing_product = function(product, added_qty, undo_option = false)
*/ */
function qty_validation(qty, uom_id) { function qty_validation(qty, uom_id) {
if (qty == null || qty == '') { if (qty == null || qty == '') {
$.notify("Il n'y a pas de quantité indiquée, ou ce n'est pas un nombre", {
globalPosition:"top right",
className: "error"});
return -1; return -1;
} }
if (uom_id == 1) { if (uom_id == 1) {
if (qty/parseInt(qty) != 1 && qty != 0) if (qty/parseInt(qty) != 1 && qty != 0){
return -2; $.notify("Une quantité avec décimale est indiquée alors que c'est un article à l'unité", {
globalPosition:"top right",
className: "error"});
return -2;}
qty = parseInt(qty); // product by unit qty = parseInt(qty); // product by unit
} else { } else {
qty = parseFloat(qty).toFixed(2); qty = parseFloat(qty).toFixed(2);
} }
if (isNaN(qty)) if (isNaN(qty)){
return -3; $.notify("Une quantité n'est pas un nombre", {
globalPosition:"top right",
className: "error"});
return -3;}
return qty; return qty;
} }
......
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