Odoo 15:覆盖已经通过 override 添加的 JS 功能

问题描述 投票:0回答:1

我正在尝试重写 Odoo 15 JS 函数,该函数已通过 Odoo 源代码中的 override 添加。

我说的是“_getLinesToAdd”函数 这是由“point_of_sale.models”(models.Order)中的“pos_coupon”模块添加的

这是 Odoo 源代码:

odoo.define('pos_coupon.pos', function (require) {
    'use strict';
const models = require('point_of_sale.models');

var _order_super = models.Order.prototype;
models.Order = models.Order.extend({

// Other code block

// This function is newly added by pos_coupon to models.Order
_getLinesToAdd: function (rewardsContainer) {
            this.assert_editable();
            return rewardsContainer
                .getAwarded()
                .map(({ product, unit_price, quantity, program, tax_ids, coupon_id }) => {
                    let description;
                    /**
                     * Improved description only aplicable for rewards of type discount, and the discount is a percentage
                     * of the price, those are:
                     * - % discount on specific products.
                     * - % discount on the whole order.
                     * - % discount on the cheapest product.
                     */
                    if (tax_ids && program.reward_type === "discount" && program.discount_type === "percentage") {
                        description =
                            tax_ids.length > 0
                                ? _.str.sprintf(
                                    this.pos.env._t("Tax: %s"),
                                    tax_ids.map((tax_id) => `%${this.pos.taxes_by_id[tax_id].amount}`).join(", ")
                                )
                                : this.pos.env._t("No tax");
                    }
                    const options = {
                        description,
                        quantity: quantity,
                        price: unit_price,
                        lst_price: unit_price,
                        is_program_reward: true,
                        program_id: program.id,
                        tax_ids: tax_ids,
                        coupon_id: coupon_id,
                    };
                    const line = new models.Orderline({}, { pos: this.pos, order: this, product });
                    this.fix_tax_included_price(line);
                    this.set_orderline_options(line, options);
                    return line;
                });
        },

});

我只是想继承并修改它,我不是添加它,我想在代码中更改。

我试过了:

odoo.define('appointment_discount_card.models', function (require) {
    'use strict';

    const models = require('point_of_sale.models');
    const rpc = require('web.rpc');

    var _super_order = models.Order.prototype;
    models.Order = models.Order.extend({
        _getLinesToAdd: function (rewardsContainer) {
        console.log('in !!!'); // It's not showing this message in the log
            this.assert_editable();
            return rewardsContainer
                .getAwarded()
                .map(({ product, unit_price, quantity, program, tax_ids, coupon_id }) => {
                    let description;
                    /**
                     * Improved description only applicable for rewards of type discount, and the discount is a percentage
                     * of the price, those are:
                     * - % discount on specific products.
                     * - % discount on the whole order.
                     * - % discount on the cheapest product.
                     */
                    if (tax_ids && program.reward_type === "discount" && program.discount_type === "percentage") {
                        description =
                            tax_ids.length > 0
                                ? _.str.sprintf(
                                    this.pos.env._t("Tax: %s"),
                                    tax_ids.map((tax_id) => `%${this.pos.taxes_by_id[tax_id].amount}`).join(", ")
                                )
                                : this.pos.env._t("No tax");
                    }
                    const options = {
                        description,
                        quantity: quantity,
                        price: unit_price,
                        lst_price: unit_price,
                        is_program_reward: true,
                        program_id: program.id,
                        tax_ids: tax_ids,
                        coupon_id: coupon_id,
                    };
                    const line = new models.Orderline({}, { pos: this.pos, order: this, product });
                    this.fix_tax_included_price(line);
                    this.set_orderline_options(line, options);
                    return line;
                });
        },
    });
});
odoo point-of-sale
1个回答
0
投票
var pos_coupon = require('pos_coupon.pos');
pos_coupon._super_order,include({...
© www.soinside.com 2019 - 2024. All rights reserved.