Переписать функцию JavaScript в Odoo 10 - PullRequest
1 голос
/ 13 апреля 2019

Я пытаюсь переписать функцию js ActionpadWidget. Вот оригинальный код:

var ActionpadWidget = PosBaseWidget.extend({
    template: 'ActionpadWidget',
    init: function(parent, options) {
        var self = this;
        this._super(parent, options);

        this.pos.bind('change:selectedClient', function() {
            self.renderElement();
        console.log("Payment Click");
        // console.log("Payment Click");
        // console.log("Payment Click");
        });
    },
    renderElement: function() {
        var self = this;
        this._super();
        this.$('.pay').click(function(){
            var order = self.pos.get_order();
            var has_valid_product_lot = _.every(order.orderlines.models, function(line){
                return line.has_valid_product_lot();
            });
            if(!has_valid_product_lot){
                self.gui.show_popup('confirm',{
                    'title': _t('Empty Serial/Lot Number'),
                    'body':  _t('One or more product(s) required serial/lot number.'),
                    confirm: function(){
                        self.gui.show_screen('payment');
                    },
                });
            }else{
                console.log("orginal elseeeeeeeeeeeeeeeeeeeeeeee");
                console.log("orginal elseeeeeeeeeeeeeeeeeeeeeeee");
                console.log("orginal elseeeeeeeeeeeeeeeeeeeeeeee");
                self.gui.show_screen('payment');
            }
        });
        this.$('.set-customer').click(function(){
            self.gui.show_screen('clientlist');
        });
    }
});

На самом деле я хочу полностью заменить функцию renderElement.

Итак, я попытался так:

screens.ActionpadWidget.include({

    renderElement: function(){
        console.log('Am here',screens.ActionpadWidget.prototype);
        this._super();
        self = this;
        this.$('.pay').click(function(){
            console.log('Am here tooo!!!')
            var order = self.pos.get_order();
            var has_valid_product_lot = _.every(order.orderlines.models, function(line){
                return line.has_valid_product_lot();
            });
            if(!has_valid_product_lot){
                self.gui.show_popup('confirm',{
                    'title': _t('Empty Serial/Lot Number'),
                    'body':  _t('One or more product(s) required serial/lot number.'),
                    confirm: function(){
                        self.gui.show_screen('payment');
                    },
                });
            }else{
                // console.log("orginal elseeeeeeeeeeeeeeeeeeeeeeee");
                // console.log("orginal elseeeeeeeeeeeeeeeeeeeeeeee");
                console.log("Sample");
                self.gui.show_screen('payment');
            }
        });

        // this._super();
    },
});

Приведенный выше код работает успешно, но только после выполнения исходного кода. Я не хочу выполнять оригинальный код.

Примечание: Я прокомментировал this._super в приведенном выше коде. На этот раз кнопка для Payment and Customer не показалась. Как мне этого добиться?

1 Ответ

0 голосов
/ 04 июня 2019
  renderElement: function() {
    var self = this;
    this._super();
    this.$('.pay').click(function(){
           var order = self.pos.get_order();
        var has_valid_product_lot = _.every(order.orderlines.models, function(line){
            return line.has_valid_product_lot();
        });
        if(!has_valid_product_lot){
           //solution
           self.gui.show_screen('products');
           //end solution
            self.gui.show_popup('confirm',{
                'title': _t('Empty Serial/Lot Number'),
                'body':  _t('One or more product(s) required serial/lot number.'),
                confirm: function(){
                    self.gui.show_screen('payment');
                },
            });
        }
        else
        {
            self.gui.show_screen('payment');
        }
    });
    this.$('.set-customer').click(function(){
        self.gui.show_screen('clientlist');
    });
}
...