I've written a Javascript funtion for the Odoo PoS, in this function I use a query to get data from a model declared in the backend python code. Inside this query function I'd like to use the discount retrieved and add it to my orderline.
But for some reason the piece of code underneath this is always generated first, which causes the discount already to be set to 0.
The "2" is always printed first and then the "1", any ideas?
render_orderline: function(orderline){
var prodgroup;
var discounts= new openerp.Model('discountgroup');
discounts.query(["discount_field"])
.filter([['productgroup','=', prodgroup]])
.first()
.then(function(discountObj){
console.log("1")
var discount;
var disc;
discount = discountObj.discount_field;
disc = Math.min(Math.max(parseFloat(discount) || 0, 0),100);
orderline.discount = disc;
orderline.discountStr = '' + disc;
});
console.log("2")
var el_str = openerp.qweb.render('Orderline',{widget:this, line:orderline});
var el_node = document.createElement('div');
el_node.innerHTML = _.str.trim(el_str);
el_node = el_node.childNodes[0];
el_node.orderline = orderline;
el_node.addEventListener('click',this.line_click_handler);
orderline.node = el_node;
return el_node;