Is it posssible to apply a part domain only when some condition is true otherwise the part domain should not be applied?
For example (extremely simplified this example):
xxx = fields.Boolean('XXX')
<field name="xxx"/>
<field name="yyy_ids" widget="many2many" domain="['|',(False,'=',xxx),(False,'!=',xxx) ]">
Example result: ValueError: Invalid leaf [False, '=', True]
otherwise writing, I need:
if xxx:
<field name="yyy_ids" widget="many2many" domain="[...version1....]"/>
else:
<field name="yyy_ids" widget="many2many" domain="[...version2....]"/>
UPDATE, SOLUTION:
@api.model
def fields_view_get(self, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
res = super(my_model, self).fields_view_get(view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
doc = etree.XML(res['arch'])
nodes = doc.xpath("//field[@name='yyy_ids']")
### if self.xxx: ### This solution does not work !!!
if 'xxx' in self._context: ### this only works
for node in nodes:
node.set('domain', "....version1....")
else:
for node in nodes:
node.set('domain', "....version2....")
res['arch'] = etree.tostring(doc)
return res
Do an onchange_xxx, which will return domain of yyy_ids.
Thx for right answer. I know but at the start? See my next question: https://www.odoo.com/forum/help-1/question/equivalent-javascript-onload-it-is-possible-when-form-is-loaded-75863