Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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="yyy_ids" widget="many2many" domain="['|',(False,'=',xxx),(False,'!=',xxx) ]">
Example result: ValueError: Invalid leaf [False, '=', True]
otherwise writing, I need:
<field name="yyy_ids" widget="many2many" domain="[...version1....]"/>
<field name="yyy_ids" widget="many2many" domain="[...version2....]"/>
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:
for node in nodes:
res['arch'] = etree.tostring(doc)
You can try that in 2 ways:
1. You can create another field, in that you store the filter value dynamically by calling onchange_event, and use this new field to filter your orginal field...
2. You can have two fields (say "yyy_ids" and "yyy1_ids" on which static domain is set respectively), then you can enable one of the field based on your criteria,..
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 2/6/15, 4:02 PM|
|Seen: 2528 times|
|Last updated: 3/16/15, 8:10 AM|