Skip to Content
Menu
This question has been flagged
2 Replies
4098 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
6329
1
Jul 16
3393
1
Jun 23
2325
0
Jan 21
2181
2
Dec 19
7749