在odoo 17 pos中,有一个名为set_discount的函数 在 models.js 文件中,我想在其中添加额外的验证,如下所示:
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;
}
我该怎么做(var maxDiscount = this.product.maxDiscount;) 在 odoo 17 js 中
您可以修补
orderline
组件
示例:
/* @odoo-modules */
import { Orderline } from "@point_of_sale/app/store/models";
import { patch } from "@web/core/utils/patch";
patch(Orderline.prototype, {
set_discount(discount) {
var self = this;
super.set_discount(discount);
var maxDiscount = self.product.maxDiscount;
if(self.discount > maxDiscount){
self.discount = 0.0;
self.discountStr = "";
}
}
})
您需要点击
Backspace
按钮才能撤消上一次操作。
在assets下添加js文件如下:
'assets': {
'point_of_sale._assets_pos': [
'MODULE_NAME/static/src/**/*',
],
},