Commit 88bbcc8e by Alexis Aoun

controle de l'input et fix des warnings de lint

parent ae99c34c
...@@ -69,6 +69,7 @@ function select_product_from_bc(barcode) { ...@@ -69,6 +69,7 @@ function select_product_from_bc(barcode) {
try { try {
if (editing_product == null) { if (editing_product == null) {
var scannedProduct = barcodes.get_corresponding_odoo_product(barcode); var scannedProduct = barcodes.get_corresponding_odoo_product(barcode);
priceToWeightIsCorrect = true; priceToWeightIsCorrect = true;
if (scannedProduct == null) { if (scannedProduct == null) {
...@@ -76,7 +77,7 @@ function select_product_from_bc(barcode) { ...@@ -76,7 +77,7 @@ function select_product_from_bc(barcode) {
return -1; return -1;
} }
var foundProduct = {data: null, place: null}; var foundProduct = {data: null, place: null};
$.each(list_to_process, function(i, e) { $.each(list_to_process, function(i, e) {
...@@ -94,27 +95,25 @@ function select_product_from_bc(barcode) { ...@@ -94,27 +95,25 @@ function select_product_from_bc(barcode) {
} }
}); });
} }
if(foundProduct.data !== null){
if(scannedProduct.rule === 'weight'){
foundProduct.data.product_qty = scannedProduct.qty;
}
else if(scannedProduct.rule === 'price_to_weight'){ if (foundProduct.data !== null) {
if (scannedProduct.rule === 'weight') {
foundProduct.data.product_qty = scannedProduct.qty;
} 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)); 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); setupPopUpBtnStyle(scannedProduct);
} }
if(scannedProduct.rule !== 'price_to_weight'){ if (scannedProduct.rule !== 'price_to_weight') {
if(scannedProduct.rule === 'weight'){ if (scannedProduct.rule === 'weight') {
editProductInfo(foundProduct.data, foundProduct.data.product_qty); editProductInfo(foundProduct.data, foundProduct.data.product_qty);
} } else {
else{
setLineEdition(foundProduct.data); setLineEdition(foundProduct.data);
} }
if (foundProduct.place === 'to_process') { if (foundProduct.place === 'to_process') {
let row = table_to_process.row($('#'+foundProduct.data.product_id[0])); let row = table_to_process.row($('#'+foundProduct.data.product_id[0]));
remove_from_toProcess(row, foundProduct.data); remove_from_toProcess(row, foundProduct.data);
} }
} }
...@@ -174,39 +173,43 @@ function update_distant_orders() { ...@@ -174,39 +173,43 @@ function update_distant_orders() {
}); });
} }
function price_to_weight_confirmed_callback (foundProduct, scannedProduct){ function price_to_weight_confirmed_callback (foundProduct, scannedProduct) {
return function price_to_weight_confirmed(){ return function price_to_weight_confirmed() {
if(priceToWeightIsCorrect){ if (priceToWeightIsCorrect) {
foundProduct.data.product_qty = scannedProduct.qty; foundProduct.data.product_qty = scannedProduct.qty;
} } else {
else{
//TODO il n'y a aucun controle sur l'input à corriger //TODO il n'y a aucun controle sur l'input à corriger
foundProduct.data.product_qty = Number((scannedProduct.value/document.getElementById("new_price_to_weight").value).toFixed(3)); var tmp = Number((scannedProduct.value/document.getElementById("new_price_to_weight").value).toFixed(3));
if (isFinite(tmp)) {
foundProduct.data.product_qty = tmp;
}
} }
if (foundProduct.data !== null) { if (foundProduct.data !== null && isFinite(tmp)) {
editProductInfo(foundProduct.data, foundProduct.data.product_qty); editProductInfo(foundProduct.data, foundProduct.data.product_qty);
if (foundProduct.place === 'to_process') { if (foundProduct.place === 'to_process') {
let row = table_to_process.row($('#'+foundProduct.data.product_id[0])); let row = table_to_process.row($('#'+foundProduct.data.product_id[0]));
remove_from_toProcess(row, foundProduct.data); remove_from_toProcess(row, foundProduct.data);
} }
resetPopUpButtons(); resetPopUpButtons();
} }
} };
} }
function price_to_weight_is_wrong(){ function price_to_weight_is_wrong() {
document.getElementById("new_price_to_weight").style.display = ""; document.getElementById("new_price_to_weight").style.display = "";
document.getElementsByClassName("btn--success")[0].style.display = "none"; document.getElementsByClassName("btn--success")[0].style.display = "none";
document.querySelector('#modal_closebtn_bottom').innerHTML = 'OK'; document.querySelector('#modal_closebtn_bottom').innerHTML = 'OK';
priceToWeightIsCorrect = false; priceToWeightIsCorrect = false;
} }
function setupPopUpBtnStyle (p){ function setupPopUpBtnStyle (p) {
//On inverse en quelque sorte les boutons succes et d'annulation en mettant "Oui" sur le btn d'annulation //On inverse en quelque sorte les boutons succes et d'annulation en mettant "Oui" sur le btn d'annulation
// et "Non" sur le bouton de reussite. // et "Non" sur le bouton de reussite.
//Cela nous permet de reecrire moins de code puisque si la reponse est Oui on ne veut //Cela nous permet de reecrire moins de code puisque si la reponse est Oui on ne veut
//rien modifier et sortir du pop up, ce qui correspond au comportement du bouton annulation //rien modifier et sortir du pop up, ce qui correspond au comportement du bouton annulation
//(ou aussi appeler cancel button) //(ou aussi appeler cancel button)
document.querySelector('#modal_closebtn_bottom').innerHTML = 'Oui'; document.querySelector('#modal_closebtn_bottom').innerHTML = 'Oui';
......
...@@ -181,7 +181,7 @@ ...@@ -181,7 +181,7 @@
<h3>Confirmation du prix</h3> <h3>Confirmation du prix</h3>
<p>Est ce que le prix au kilo du produit <b><span id="product_to_verify"></span></b> <p>Est ce que le prix au kilo du produit <b><span id="product_to_verify"></span></b>
est bien <b><span id="price_to_verify"></span></b> euros/Kg ?</p> est bien <b><span id="price_to_verify"></span></b> euros/Kg ?</p>
<textarea name="Prix au Kilo" id="new_price_to_weight" cols="3" rows="1"></textarea> <input type="number" min="0.00001" name="Prix au Kilo" id="new_price_to_weight">
</div> </div>
</div> </div>
<br/> <br/>
......
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