Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
5 Răspunsuri
5292 Vizualizări

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...

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Autor

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

Autor

Ok, please give me some example to refactor my code

edited on the answer

Autor

doesn't return values

Related Posts Răspunsuri Vizualizări Activitate
0
mai 24
1056
0
iul. 25
263
1
iul. 25
5037
0
iul. 25
596
0
iun. 25
681