تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
12977 أدوات العرض

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

الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
أفضل إجابة

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.

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

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
مارس 16
4864
3
أغسطس 17
9487
3
سبتمبر 25
14038
1
أغسطس 25
2551
0
يناير 25
1344