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

i've created many2many field with hr.employee in custom model,

but i need to get the ids of the selected many2many fields,

any idea how to do that ?

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

Hi @loay elhaj

let suppose you have created the field employee_ids in your cutom model as test.
employee_ids = fields.Many2many('hr.employee', 'employee_test_rel', 'test_id', 'emp_id', string='Employees')

to get the ids of the selected employees in many2many field, you have to do
self.employee_ids.ids
this will return a list of selected employee ids ([6,889,90] for example)

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

Thank you it's working,
but I'm wondering can ORM method .browse accept passing list as filter for searching ?

Yes @loay elhaj self.browse only accept LIST OF IDS or RECORD ID
[ self.browse([7, 18, 12]) OR self.browse(2) ]

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 9 23
1921
1
thg 12 22
3429
0
thg 10 21
3064
2
thg 3 21
4816
2
thg 3 21
4033