콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
2624 화면

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


아바타
취소
베스트 답변

Hi,

To Add additional validation in the `set_discount` function in Odoo 17 POS, when using `var maxDiscount = this.product.maxDiscount`, it is essential to import the required classes and an Error Popup to facilitate proper validation. Following this, you can modify the code as outlined below:


import { Orderline } from "@point_of_sale/app/store/models";
import { patch } from "@web/core/utils/patch";import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup";

patch(Orderline.prototype, {
    async 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);
        var maxDiscount = this.product.maxDiscount;
        if (disc > maxDiscount) {
            await this.env.services.popup.add(ErrorPopup, {
                title: _t("Exceed Discount Limit!"),
                body: _t("Sorry, Discount is not allowed. Maximum discount for this Product is %s %", maxDiscount),
            });
            this.discount = 0;
            this.discountStr = "0";
        } else {
            this.discount = disc;
            this.discountStr = "" + disc;
        }
    }


Regards

아바타
취소
관련 게시물 답글 화면 활동
1
3월 24
1727
2
1월 20
11350
2
8월 25
634
0
7월 22
2873
0
6월 18
3602