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

JavaScript doesn't return a value

By
Jo
on 9/22/15, 7:57 AM 659 views

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

1

Axel Mendoza

--Axel Mendoza--
10298
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 9/22/15, 9:54 AM

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

Jo
on 9/22/15, 1:16 PM

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

Axel Mendoza
on 9/22/15, 1:24 PM

Ok, please give me some example to refactor my code

Jo
on 9/22/15, 1:31 PM

edited on the answer

Axel Mendoza
on 9/22/15, 2:02 PM

doesn't return values

Jo
on 9/23/15, 2:27 AM

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

2 follower(s)

Stats

Asked: 9/22/15, 7:57 AM
Seen: 659 times
Last updated: 9/22/15, 3:34 PM