Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
7825 Tampilan

Hi,

 I want to add some features to POS but I'm not familiar to js. 

So for PaymentScreenWidget I was able to add some new functions and to change others, like this :

function openerp_vi_pos_print_invoice(instance, module){
var QWeb = instance.web.qweb;
var _t = instance.web._t;
console.log('print_');
console.log(module);
module.PaymentScreenWidget.include({
init: function(parent, options) {
var self = this;
this._super(parent,options);
//console.log('Init!!!!');
},
show: function(){
this._super();
var self = this;
this.add_action_button({
label: _t('Print Inv.'),
name: 'b_invoice',
icon: '/vi_pos/static/src/img/icons/print.png',
click: function(){
self.print_invoice_func({invoice_vi: true, invoice:true});
},
});
this.update_payment_summary();
},
print_invoice_func: function(options) {
var self = this;
options = options || {};
var currentOrder = this.pos.get('selectedOrder');
//console.log(options.invoice_vi && options.invoice);
if (options.invoice_vi && options.invoice) {
self.validate_order({invoice: options.invoice, invoice_vi:options.invoice_vi});
}
},
update_payment_summary: function() {
this._super();
if(this.pos_widget.action_bar){
this.pos_widget.action_bar.set_button_disabled('b_invoice', !this.is_paid());
}
},
 });
}


But when I tried to the same to PosModel:

function openerp_vi_pos_models(instance, module){ //module is instance.point_of_sale
var QWeb = instance.web.qweb;
var _t = instance.web._t;
module.PosModel.include({

new_func: function(order){
var self = this;
var invoiced = new $.Deferred();
if(!order.get_client()){
invoiced.reject('error-no-client');
return invoiced;
}
var order_id = this.db.add_order(order.export_as_JSON());
            ....
             ....
},
});
}


I get an error Uncaught TypeError: module.PosModel.include is not a function

So I print the variable module through console.log(module); and I notice that "PaymentScreenWidget" it has defined the include function and the "prototype" is Class and in PosModel we don't have the function include and the prototype is Surrogate.

If I don't have the include function how do I add a function to PosModel?

Thanks 



Avatar
Buang
Jawaban Terbai

Please refers to this answers for examples of how to do it for get your code called:

https://www.odoo.com/forum/help-1/question/how-to-modify-the-behavior-of-the-enter-key-in-the-pos-interface-93881#answer_93884

https://www.odoo.com/forum/help-1/question/how-to-choose-different-pos-xml-according-to-login-user-or-company-81025#answer_91974

Also notice that module.PosModel is a Backbone Model so it don't have include like the rest of Odoo classes, try to extending using the Backbone set function or directly manipulating the object prototype, as Backbone docs says it's ok to do it

Avatar
Buang
Penulis

The links that you gave are all related to module.PaymentScreenWidget.include, in this case I know how to do it... I just don't know how to do it for PosModel...

What I try to show you is that maybe you need to change the file declaration to get your code called by Odoo

I update my answer with other tips

if you solve it, please share the results so others could find it useful

Post Terkait Replies Tampilan Aktivitas
2
Jul 24
2294
0
Mei 24
1821
5
Sep 20
31715
0
Agu 19
6336
1
Des 23
1869