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

hi all,

how i can add filter (domain) for a field with onchange of another field


1) field1: a Many2one field select a value (its a Transient field if i can add as Many2one)

2) field2: another Many2one field set filter to select as selected in field1


regards

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

Hi,
You can add a domain based on the onchange of another field as shown below.

@api.onchange(‘field1’)
def _onchange_field1(self):
    return {'domain': {field_2: [(‘field1’, ‘=’, field1.id)]}}

Here you can change condition based on your scenario.
Regards,

อวตาร
ละทิ้ง

this is deprecated in odoo14

ผู้เขียน

@Niyas Raphy

then what is implemented, please can you show us, this will help a lot.

As Niyas Raphy pointed out, @api.onchange returning a domain is deprecated in v14 (working for now, but logs a warning message). For a simple domain filter like this, use the domain attribute on the field in the form view.

<field name="field1"/>

<field name="field2" domain="[('field1', '=', field1)]"/>

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
เม.ย. 23
2835
2
ก.พ. 25
40547
2
พ.ย. 22
2884
2
ธ.ค. 21
4175
0
ต.ค. 21
2286