В Odoo 17 pos_discount я хочу включить функцию apply_discount, чтобы добавить дополнительную проверку.
Это исходный код модуля pos_discount Odoo 17. Я хочу расширить функцию apply_discount в новом модуле с именем rgb_sale_update, чтобы добавить некоторую проверку перед применением скидки.
/** @odoo-module **/
import { _t } from "@web/core/l10n/translation";
import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen";
import { useService } from "@web/core/utils/hooks";
import { NumberPopup } from "@point_of_sale/app/utils/input_popups/number_popup";
import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup";
import { Component } from "@odoo/owl";
import { usePos } from "@point_of_sale/app/store/pos_hook";
export class DiscountButton extends Component {
static template = "pos_discount.DiscountButton";
setup() {
this.pos = usePos();
this.popup = useService("popup");
}
async click() {
var self = this;
const { confirmed, payload } = await this.popup.add(NumberPopup, {
title: _t("Discount Percentage"),
startingValue: this.pos.config.discount_pc,
isInputSelected: true,
});
if (confirmed) {
const val = Math.max(0, Math.min(100, parseFloat(payload)));
await self.apply_discount(val);
}
}
async apply_discount(pc) {
// here i want to add my validation
}
}
ProductScreen.addControlButton({
component: DiscountButton,
condition: function () {
const { module_pos_discount, discount_product_id } = this.pos.config;
return module_pos_discount && discount_product_id;
},
});
Я все больше и больше пытался его наследовать, но в Odoo 17 это не работает. Мне нужна помощь.
обновления
/** @odoo-module */
import { DiscountButton } from "@pos_discount/overrides/components/discount_button/discount_button";
import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup";
import { patch } from "@web/core/utils/patch";
import { _t } from "@web/core/l10n/translation";
patch(DiscountButton.prototype, {
async apply_discount(pc) {
console.log("test")
await super.apply_discount(arguments);
},
});
я пробовал патчить тоже не помогло