Odoo Help

0

How to include some functions in PosModel?

By
Anabela Damas
on 12/7/15, 9:15 AM 1,244 views

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 



0
Axel Mendoza
On 12/9/15, 2:41 AM

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

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...

Versão Integral, Anabela Damas
on 12/9/15, 4:08 AM

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

Axel Mendoza
on 12/9/15, 4:10 AM

I update my answer with other tips

Axel Mendoza
on 12/9/15, 5:06 AM

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

Axel Mendoza
on 12/10/15, 5:25 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 12/7/15, 9:15 AM
Seen: 1244 times
Last updated: 12/9/15, 2:41 AM