Odoo覆盖pos_discount模块中的函数/无法在我的自定义模块中继承pos_discount模块

时间:2019-07-17 09:45:16

标签: javascript odoo odoo-11

我试图在自定义模块的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函数。

请帮助。在此先感谢

0 个答案:

没有答案