コンテンツへスキップ
メニュー
この質問にフラグが付けられました
5 返信
5104 ビュー

Hi all,

Here i want return all partners in odoo to stock picking by JavaScript.

get_partners: function(){

    var self = this;

    var model = new instance.web.Model('res.partner');

    this.partners = [];

    return model.query(['id', 'name']).filter([['customer', '=', 'True']]).limit(1000).all().then(function(partners){

        _.each(partners, function(partner){

        self.partners.push(partner);

        });

        });

    },

This code perfectly fetching all partners, but doesn't return the arrays. please give me suggestions.

thanks in advance...

アバター
破棄
最善の回答

What you are returning is a promise of the deferred returned by all() that could be used when the returned promise get resolved in the same way that the function argument used on then execution. You could also create a deferred to be returned and resolve with the values of partners, that way you could return a more direct object to the results but outside of get_partners there need to be some code attached to the deferred or promise on done/then/etc to get to resolved values

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

How it will work?

get_partners: function(){
var self = this;
var model = new instance.web.Model('res.partner'); 
var result = $.Deferred();
return model.query(['id', 'name']).filter([['customer', '=', 'True']]).limit(1000).all(); 
},
use_of_get_partners: function(){
var self = this;
self.partners = [];
this.get_partners().done(function(partners){
#here you can use the partners when get_partners promise is done
_.each(partners, function(partner){
self.partners.push(partner);
});
#do what you need to do with the partners directly here
})
}

I like the same but this is the way you could get the partners outside get_partners function. Also with your code you could do the same by directly using the partners result

アバター
破棄
著作者

Please, give me brief explanation. thanks

all depends on how are you using your get_partners function. let me update my answer with an example of how (I think) you need to refactor your code

著作者

Ok, please give me some example to refactor my code

edited on the answer

著作者

doesn't return values

関連投稿 返信 ビュー 活動
0
5月 24
813
1
6月 25
383
1
6月 25
329
1
5月 25
916
0
3月 25
529