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

Hello, in Odoo 8 i created @api.onchange function that sets domain to many2one field if another field is changed. This works OK so far but the problem is if editing existing records.

For example if i have Selection field with options Yes and No and if Yes is selected then Many2one field must allow only ids 1,2,3. If No is selected the Many2one must allow 4,5.

Changing Selection applies the domain to Many2one.

If i edit already saved record having Selection=Yes i see all the values 1,2,3,4,5 in Many2one.

Why onchange and domain is not applied when editing records?

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

Hi, 

You can watch following video for this:

https://youtu.be/ezH3ql5Dmx4

Thanks

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

since the beginning, it's not a decent solution to add dynamic domain. there is no communication between server-client when view mode change.
Odoo is removing all the dynamic domain from V14 :)
https://github.com/search?q=org%3Aodoo+dynamic+domain&type=Issues

have to add domain on many2one field with like 

options = fields.Selection(....)
my_m2o_id = fields.Many2one('my.model', domain=[('options',  '=?', options)])

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Ah ok, this is an idea. 

I will add another field in my many2one model indicating the current value for which options is allowed and will assign the new fields values a per our needs. Thank you.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
มิ.ย. 25
418
3
พ.ค. 24
5419
2
ม.ค. 16
5206
How to set domain in field on page load? แก้ไขแล้ว
3
ธ.ค. 22
7727
2
ก.ค. 22
11882