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

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 ?

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

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)

الصورة الرمزية
إهمال
الكاتب

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) ]

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
سبتمبر 23
1989
1
ديسمبر 22
3473
0
أكتوبر 21
3158
2
مارس 21
4876
2
مارس 21
4051