Odoo Help

Welcome!

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

0

How to include some functions in PosModel?

By
Anabela Damas
on 12/7/15, 9:15 AM 688 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

--Axel Mendoza--
10205
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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