Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
12577 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 3 16
4550
3
thg 8 17
9090
1
thg 7 25
2183
0
thg 1 25
1041
2
thg 11 24
11767