首页 > 解决方案 > Odoo 覆盖 pos_discount 模块中的函数/无法在我的自定义模块中继承 pos_discount 模块

问题描述

我试图pos_discount在我的自定义模块中覆盖模块中的 js 函数。我试过这样:

odoo.define('bake_v11.xn_global_discount', function (require) {
"use strict";
var mod_discount = require('pos_discount.pos_discount');
console.log(mod_discount)
});

但我无法获取mod_discount变量中的数据。它显示undefined在控制台中。我在js方面没有太多经验。

及其展示

Failed modules:["bake_v11.xn_global_discount"]

在控制台中。

我在文件中添加了pos_discount模块。manifest我不知道哪里出错了。

完整代码

odoo.define('bake_v11.xn_global_discount', function (require) {
"use strict";
var moddiscount = require('pos_discount.pos_discount');
console.log(moddiscount);
var gui = require('point_of_sale.gui');
var rpc = require('web.rpc');
var core = require('web.core');
var screens = require('point_of_sale.screens');
var _t = core._t;

moddiscount.DiscountButton = moddiscount.DiscountButton.include({

    apply_discount: function(pc) {
        var order    = this.pos.get_order();
        var lines    = order.get_orderlines();
        var product  = this.pos.db.get_product_by_id(this.pos.config.discount_product_id[0]);
        if (product === undefined) {
            this.gui.show_popup('error', {
                title : _t("No discount product found"),
                body  : _t("The discount product seems misconfigured. Make sure it is flagged as 'Can be Sold' and 'Available in Point of Sale'."),
            });
            return;
        }

        // Remove existing discounts
        var i = 0;
        while ( i < lines.length ) {
            if (lines[i].get_product() === product) {
                order.remove_orderline(lines[i]);
            } else {
                i++;
            }
        }

        // Add discount
        // We add the price as manually set to avoid recomputation when changing customer.
        var discount = - pc / 100.0 * order.get_total_with_tax();
        console.log(pc)

        if( discount < 0 ){
            order.add_product(product, {
                price: discount,
                extras: {
                    price_manually_set: true,
                },
            });
        }
    },



});

});

我的要求:我想编辑apply_discount功能。

请帮忙。提前致谢

标签: javascriptodooodoo-11

解决方案


推荐阅读