Как показать ошибку всплывающего окна в точке продаж в odoo 12 - PullRequest
0 голосов
/ 17 апреля 2020

Я хочу запретить пользователю добавлять больше товаров для продажи, если заказ помечен как заказной. Я хочу показать всплывающее сообщение об ошибке, когда заказ оформлен, и пользователь по-прежнему нажимает на товар

здесь мой код

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

1 Ответ

1 голос
/ 18 апреля 2020

Вы можете получить доступ к gui через posModel.

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

Вы можете проверить пример на connect_to_proxy

...