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 Inherit POS javascript method from db.js?

By
Vinod Singh
on 10/13/15, 5:43 AM 984 views

I need to override a method from POS javascript file(db.js) search_product_in_category. I tried it using following code but no luck.

function pos_advance_search(instance, module){

var PosDBSuper = module.PosDB
module.PosDB = module.PosDB.include({
load_server_data: function(){
var self = this;
var loaded = PosDBSuper.prototype.load_server_data.call(this);
return loaded; 
},

search_product_in_category: function(category_id, query){
res=[]

// some code goes here....

return res;

},
});
},

(function(){
var _super = window.openerp.point_of_sale;
window.openerp.point_of_sale = function(instance){
_super(instance);
var module = instance.point_of_sale;

pos_advance_search(instance, module);

}
})()

0
Lithin T
On 10/13/15, 8:00 AM
openerp.YOUR_CUSTOM_MOUDLE_NAME = function (instance) {
var _t = instance.web._t;
var QWeb = instance.web.qweb;
var module = instance.point_of_sale;

module.PosDB.include({
init: function(options){
var self = this;
this._super();
},

search_product_in_category: function(category_id, query){

//You can add your custom code here

try {
query = query.replace(/[\[\]\(\)\+\*\?\.\-\!\&\^\$\|\~\_\{\}\:\,\\\/]/g,'.');
query = query.replace(/ /g,'.+');
var re = RegExp("([0-9]+):.*?"+query,"gi");
}catch(e){
return [];
}
var results = [];
for(var i = 0; i < this.limit; i++){
r = re.exec(this.category_search_string[category_id]);
if(r){
var id = Number(r[1]);
results.push(this.get_product_by_id(id));
}else{
break;
}
}
return results;
},
});


};

Dear Vinod,
you can try the above method.

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: 10/13/15, 5:43 AM
Seen: 984 times
Last updated: 10/13/15, 8:00 AM