繁体   English   中英

如何在 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记录到我的控制台时,output undefined

您可以通过posModel访问gui

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

您可以在connect_to_proxy查看示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM