Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
5 Odpowiedzi
5268 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
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

Powiązane posty Odpowiedzi Widoki Czynność
0
maj 24
1048
0
lip 25
209
1
lip 25
4975
0
lip 25
511
0
cze 25
618