Skip to Content
Menu
This question has been flagged
2 Replies
3570 Views

I need a little help on Odoo widget. I have this in js file...

_format: function (row_data, options) {

this.session = session;

if (!row_data[this.id] || !row_data[this.id].value) {

return '';

}

var arraygiven = [];

new model('sale.order.line').query(['order_id']).filter([['product_id', '=', row_data[this.id].value]]).all().then(function (records) {

for(var i = 0, len = records.length; i < len; i++){

arraygiven.push(records[i].order_id[1]);

}

//console.log(arraygiven);//arraygiven is shown in console

});

//console.log(arraygiven); //arraygiven is not shown in console

return QWeb.render('producthistorylist', {widget: this, saleorderlinenum: arraygiven});

}

How can i stop further process until i get the value from ajax request i.e. in "arraygiven" in above code? I have to return Qweb.render(....) after the value of arraygiven is received from ajax request?

Avatar
Discard
Best Answer

You have a problem with the function itself. This function is designed to format the data in the client, not to get more that from the server. If you need more data to format it correctly you will need to find the correct function to load all the data from the server and call the format function once all data is the client.

About the Deffered idea, it works, but it doesnt work. Looks like you dont understand them either. The return you have in the "then" function is not the return of the "_format" function. In your code the "_format" function don't have  a return value.

As i said it work, if you console.log(Qweb....) it will print, but not place in the document.

Avatar
Discard
Best Answer

=======================

Below Code May Help You

=======================

_format: function (row_data, options) {

this.session = session;

if (!row_data[this.id] || !row_data[this.id].value) {

return '';

}

var self = this;

var call_done = $.Deferred();

var arraygiven = [];

new model('sale.order.line').query(['order_id']).filter([['product_id', '=', row_data[this.id].value]]).all().then(function (records) {

for(var i = 0, len = records.length; i < len; i++){

arraygiven.push(records[i].order_id[1]);

}

call_done.resolve(arraygiven);

});

call_done.then(function (values) {

console.log(values); // YOUR VALUES(arraygiven) ARE COME HERE

return QWeb.render('producthistorylist', {widget: self, saleorderlinenum: values});

});

}

Avatar
Discard
Related Posts Replies Views Activity
1
May 23
4873
1
Jul 16
2755
1
Jun 23
1592
0
Jan 21
1731
2
Dec 19
6996