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.

1

How to read the res.partner ids in javascript?

By
Jo
on 9/21/15, 3:03 PM 1,238 views

Hello all, here i want drop-down the partners in stock picking by javascript.

Here is i tried code, please give me a suggestions.

*.xml:

<select>

   <t t-for-each="widget.get_partners()" t-as="partner">

     <option value="partner.id"> <t t-esc="partner.name"> </t> </option>

</select>


widget.js:

get_partners: function(){

    var self = this;

    var partners = [];

    new instance.web.Model('res.partner').call('search_read', [[['customer', '=', 'True']], 0, '', {}, '']).then(function(result){

        _.each(result, function(partner){

            partners.push({id: partner.id, name: partner.name,})

            });

        });

    return partners;

},


but i'm not getting any value in drop-down.

thanks in advance..

5
Ayaz Mansuri
On 3/2/16, 5:09 AM

Hello...!!!

You Have to push models in your js file like,

module.Model.prototype.models.push({

    model: 'res.partner',

    fields: ['partner_id','name'],

    loaded: function(self,partners){

    self.partners = partners; 

},

});


And Write in Your XML File,

                <select name='partner_id'>

                          <option value=''>None</option>

                                 <t t-foreach='widget.partners' t-as='partner'>

                                        <option t-att-value='partner.id' >

                                        <t t-esc='partner.name'/>

                </option>

            </t>

</select>

Here you got partner name in your drodown list...!!!

Regards,

Ayaz Mansuri

0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 9/22/15, 1:54 AM

Hi, you can call ORM search method to get the partner ids.....

and name_get method to get their names !

new instance.web.Model(''res.partner').call('search', [[[YOUR_DOMAIN(optional)]], 0, '', {}, ''])

.then(function(result){

console.log(result); //partner ids

new instance.web.Model('res.partner').call('name_get', [result])

.then(function(partner_names){

console.log(partner_names); // names of all the partners in array of array structure :- [[],[],[]]

})

});

Regards

thanks pawan, this give partner ids, and i want their name and id in list. please give some definition of your above code.

Jo
on 9/22/15, 2:40 AM

you can call name_get on the ids returned.. check my updated answer

Pawan
on 9/22/15, 5:39 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

1 follower(s)

Stats

Asked: 9/21/15, 3:03 PM
Seen: 1238 times
Last updated: 3/2/16, 5:19 AM