in odoo 17 pos, there is a function named set_discount in models.js file , i want to add extra validation in it like this :
set_discount(discount) {
var parsed_discount =
typeof discount === "number"
? discount
: isNaN(parseFloat(discount))
? 0
: oParseFloat("" + discount);
var disc = Math.min(Math.max(parsed_discount || 0, 0), 100);this.product.id });
//here i want to get max discount from product.product
//var maxDiscount = this.product.maxDiscount;
//if(disc > maxDiscount){
//alert("discount > max discount");
//return;
//}
this.discount = disc;
this.discountStr = "" + disc;
}
how can i do this (var maxDiscount = this.product.maxDiscount;) in odoo 17 js
You can patch the
orderline
componentExample:
You need to click the
Backspace
button to undo the last operation.Add the js file under assets as follows:
You can use the pos popup to show notifications to users
Example:
Edit:
Override the
_loader_params_product_product
function to force Odoo to set the value of the product max discountExample:
Use the same field name (
this.product.max_discount
) in js code