如何在 odoo 12 的销售点中显示弹出错误

How to show popup error in Point of Sale in odoo 12

如果订单被标记为预订订单,我想限制用户添加更多产品进行销售 我想在预订订单时显示弹出错误消息,但用户仍然点击该产品

这是我的代码

odoo.define('tw_pos_inherit_model.attemptInherit', function (require) {
    "use strict";
    var POSInheritmodel = require('point_of_sale.models');
    var ajax = require('web.ajax');
    var BarcodeParser = require('barcodes.BarcodeParser');
    var PosDB = require('point_of_sale.DB');
    var devices = require('point_of_sale.devices');
    var concurrency = require('web.concurrency');
    var config = require('web.config');
    var core = require('web.core');
    var field_utils = require('web.field_utils');
    var rpc = require('web.rpc');
    var session = require('web.session');
    var time = require('web.time');
    var utils = require('web.utils');
    var gui = require('point_of_sale.gui');
    var orderline_id = 1;

    var QWeb = core.qweb;
    var _t = core._t;
    var Mutex = concurrency.Mutex;
    var round_di = utils.round_decimals;
    var round_pr = utils.round_precision;
    var _super_order = POSInheritmodel.Order.prototype;
    POSInheritmodel.Order = POSInheritmodel.Order.extend({
        add_product: function(product, options){
            var can_add = true;
            var changes = this.pos.get_order();
            var self = this;
            try{
                if(changes.selected_orderline.order.quotation_ref.book_order){
                    can_add= false;
                }
            }catch(err){}
            if (can_add){
                if(this._printed){
                    this.destroy();
                    return this.pos.get_order().add_product(product, options);
                }
                this.assert_editable();
                options = options || {};
                var attr = JSON.parse(JSON.stringify(product));
                attr.pos = this.pos;
                attr.order = this;
                var line = new POSInheritmodel.Orderline({}, {pos: this.pos, order: this, product: product});

                if(options.quantity !== undefined){
                    line.set_quantity(options.quantity);
                }

                if(options.price !== undefined){
                    line.set_unit_price(options.price);
                }

                //To substract from the unit price the included taxes mapped by the fiscal position
                this.fix_tax_included_price(line);

                if(options.discount !== undefined){
                    line.set_discount(options.discount);
                }

                if(options.discount_percentage !== undefined){
                    line.set_if_discount_percentage(options.discount_percentage);
                }

                if(options.discount_amount !== undefined){
                    line.set_if_discount_amount(options.discount_amount);
                }

                if(options.extras !== undefined){
                    for (var prop in options.extras) {
                        line[prop] = options.extras[prop];
                    }
                }

                var to_merge_orderline;
                for (var i = 0; i < this.orderlines.length; i++) {
                    if(this.orderlines.at(i).can_be_merged_with(line) && options.merge !== false){
                        to_merge_orderline = this.orderlines.at(i);
                    }
                }
                if (to_merge_orderline){
                    to_merge_orderline.merge(line);
                } else {
                    this.orderlines.add(line);
                }
                this.select_orderline(this.get_last_orderline());

                if(line.has_product_lot){
                    this.display_lot_popup();
                }
            }else{
                self.gui.show_popup('error',{
                    title :_t('Modification Resctricted'),
                    body  :_t('Booked Order cannot be modified'),
                });
            }
        },

    });
});

但是我遇到了一个错误

Uncaught TypeError: Cannot read property 'show_popup' of undefined
http://localhost:8071/web/content/554-cbfea6c/point_of_sale.assets.js:475
Traceback:
TypeError: Cannot read property 'show_popup' of undefined
    at child.add_product (http://localhost:8071/web/content/554-cbfea6c/point_of_sale.assets.js:475:116)
    at Class.click_product (http://localhost:8071/web/content/554-cbfea6c/point_of_sale.assets.js:326:257)
    at Object.click_product_action (http://localhost:8071/web/content/554-cbfea6c/point_of_sale.assets.js:325:951)
    at HTMLElement.click_product_handler (http://localhost:8071/web/content/554-cbfea6c/point_of_sale.assets.js:320:1738)

对不起,我真的很困惑,我还需要先初始化 this.gui 吗?

尽管我已经 var gui = require('point_of_sale.gui'); 初始化了

当我将 this.gui 记录到我的控制台时,输出是 undefined

您可以通过 posModel 访问 gui

self.pos.gui.show_popup('error',{
                title :_t('Modification Resctricted'),
                body  :_t('Booked Order cannot be modified'),
            });

您可以在 connect_to_proxy

查看示例