Reputation: 1108
I try to set invisible attribute to a field depending on a field in many2one relation:
In fact, I have a model M1 with a field option and a field m2_id which is a m2o relation to model M2 that contains a field category (a selection field with values val1/val2)
M1: option (text), m2_id (many2one)
M2: category (selection)
My purpose is to show/hide the field option depending on the value of m2.category
Normally this must work:
<field name="m2_id" />
<field name="option" attrs="{'invisible': [('m2_id.category','=','val1')]}" />
But this generates a runtime error:
Error: unknown field m2_id.category in domain [["m2_id.category","=","val1"]]
I tried to set the attribute directly like this:
<field name="option" invisible="[('m2_id.category','=','val1')]" />
but it expects a value not an expression. so, it's considered as True all the time.
Please any idea or suggestion ?
Upvotes: 4
Views: 4757
Reputation: 11143
you may make related field for it and than add field on a attrs after than it will work fine.
For example:
'category': fields.related('m2_id', 'category', type="char", relation='target_table_name', readonly=True, string="Category"),
now use in xml like
<field name="m2_id" />
<field name="category" invisible="1"/>
<field name="option" attrs="{'invisible': [('category','=','val1')]}" />
Upvotes: 2