コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
7842 ビュー

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

関連投稿 返信 ビュー 活動
2
4月 23
2723
2
2月 25
40423
2
11月 22
2808
2
12月 21
4092
0
10月 21
2253