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

Hello everyone.

I have a problem obtaining partners using the Odoo webapi. Now the method that I do in my application is doing a bucle of all my ids and, for every id, calling the webapi passing the Id to get the partner.

For example:

for ( i=0; i<partners.length; i++)

     loadPartner(partner(i).id)

In terms of time, this are so slow and heavy (if you have 100 partners, you will do 100 webapi calls). I looked for this in the documentation but I don't see anything about this. So, exists the possibility for get all partners by passing a list of ids? I think that this will be more efficient and fast.

Ảnh đại diện
Huỷ bỏ

Thank you @Odoo Tools, it worked like a charm :)

Câu trả lời hay nhất

To get all (active) partner ids: 

self.env['res.partner']._search([]) #You can add this to your Python method and trigger this from JS using RPC. 

To get partner recordest using IDS: 

self.env['res.partner'].browse(IDS). 


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

the answer depends on the implementation of loadPartner, can it handle a list of ids?

I assume that `partners` is an array of object.

partner_ids = _.pluck(partners, 'id');
if (partner_ids.length) {
   loadPartner(partner_ids)                            
}

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 25
591
2
thg 7 25
1147
1
thg 6 25
798
1
thg 4 25
973
1
thg 3 25
1182