How to check if one2many field is empty in openerp xml views
I am trying to make some field invisible if the other field (which is equal to one) has no value (empty).
I am trying something like
<field name="reference" invisible="{'line_ids', '=', False}"/>
Also tried
<field name="reference" invisible="{'line_ids', 'in', []}"/>
Finally
<field name="reference" invisible="{'line_ids', '=', None}"/>
Note: line_ids is one 2many field
But it didn't work out. Someone please suggest if possible.
source to share
I have the same problem. I tried to use Emipro solutions but doesn't work (but you should still use "attrs" instead of invisible).
Also, I tried with
[('line_ids', '=', [(0, 0, [])])]
and
[('line_ids', '=', [(6, False, [])])]
but nothing worked.
Eventually I ended up creating a boolean computed field
self.line_count = len(self.line_ids) > 0
and works with a simpler condition
[('line_count', '=', False)]
if someone suggests a correct solution ...
source to share
On the One2many field in Odoo 10 I just tested myself and an empty list works as in:
attrs="{'invisible': [('item_ids', '=', [])]}"
I heard from other people that above this works for Odoo 9 too. For Odoo 8 I also used:
attrs="{'invisible': [('item_ids', '=', [(6, False, [])])]}"
... with success. If any of these don't work for you and your version, try updating the source code. Also, for Odoo 7, an empty path should work (but I haven't tried it myself). It was weird how they went from [] to [(6, False, [])])] and then back to [].
source to share