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

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

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Autor

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

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

Related Posts Răspunsuri Vizualizări Activitate
2
mar. 16
4550
3
aug. 17
9087
1
iul. 25
2179
0
ian. 25
1040
2
nov. 24
11766