this is the original code :
/** @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 som validation
}
}
ProductScreen.addControlButton({
component: DiscountButton,
condition: function () {
const { module_pos_discount, discount_product_id } = this.pos.config;
return module_pos_discount && discount_product_id;
},
});
and this is my code
/** @odoo-module **/
const _t = require("@web/core/l10n/translation")._t;
const ProductScreen = require("@point_of_sale/app/screens/product_screen/product_screen").ProductScreen;
const NumberPopup = require("@point_of_sale/app/utils/input_popups/number_popup").NumberPopup;
const ErrorPopup = require("@point_of_sale/app/errors/popups/error_popup").ErrorPopup;
const Component = require("@odoo/owl").Component;
const usePos = require("@point_of_sale/app/store/pos_hook").usePos;
const DiscountButton = require("@pos_discount/overrides/components/discount_button/discount_button").DiscountButton;
export class CustomDiscountButton extends DiscountButton {
async apply_discount(pc) {
console.log('some validation');
await super.apply_discount(pc);
}
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);
}
}
}
ProductScreen.addControlButton({
component: CustomDiscountButton,
condition: function () {
const { module_pos_discount, discount_product_id } = this.pos.config;
return module_pos_discount && discount_product_id;
},
});
/** @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);
},
});
should this code work ?