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

I have connected res_users and res_partner with a many2many relation, so every user has his contacts that he is responsible for and a contact can be in different users.

My problem is that I can't figure out how to get all res_partner ids that are in relation with a user. I need this in a website so it needs to work in a controller. That's why I can't just query it. Can someone help me with this? I need only ids of the partners so I can use that in a search([('partner_id', 'IN', users_contact_ids)])

# Field in res.users model
res_partner_ids = fields.Many2many('res.partner', relation='res_users_partners_rel', column1='res_users_id', column2='res_partner_id', string='Contacts on user')
 


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

OK, I figured it out... the main problem was that I didn't get all the contacts. So I used sudo and it worked.

users_contacts = user.sudo().res_partner_ids.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 12 22
15521
1
thg 4 20
142
1
thg 6 19
3788
0
thg 2 19
3307
2
thg 6 18
89