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

Further process if only ajax request is complete and value is received in widget

By
Manoj Bhattarai
on 4/19/16, 5:15 AM 293 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?

0
Jorge Barcelo Cortes
On 4/22/16, 6:56 AM

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.

0
Jigar Patel
On 4/22/16, 6:01 AM

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

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});

});

}

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: 4/19/16, 5:15 AM
Seen: 293 times
Last updated: 4/24/16, 4:27 PM