Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
11174 มุมมอง

Hello there, 

I'm trying to create a domain on a Many2many field:

@api.onchange('name')
def onchange_domain_on_days(self):
res = {}
ids = []
employee_model = self.env['hr.employee']
all_employees = employee_model.search([])
for employee in all_employees:
if employee.user_id.store_id == self.working_hours_id.store_id:
ids.append(employee.id)
res['domain'] = {
'monday': [('id', 'in', ids)],
}
return res


This will work very well! BUT only if the field value 'name' changes.. Is there a way to apply this from the beginning?

Best regards

--

Alejandro

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

- One option is to make it a compute field of type Many2many. And you can add the above code on that function, according to what should be returned on that field.

- Another option is to override the view_init() which is triggered everytime showing a form view, you can add your code in that function.

This post also might be helpful, which describes another way:

https://www.odoo.com/es_ES/forum/help-1/question/how-to-apply-domain-filter-on-many2many-field-28988 


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
พ.ย. 22
80
1
มิ.ย. 22
7561
Many2many domain not working แก้ไขแล้ว
1
ก.ค. 21
3085
Many2many domain not working แก้ไขแล้ว
1
ก.ค. 21
4562
9
ก.พ. 16
49660