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.

+3


source to share


5 answers


Try the following,

<field name="reference" attrs="{'invisible' :[('line_ids', '=', False)]}"/>

      



This is the behavior of attrs in odoo, version by version is different.

enter image description here

+7


source


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 ...

+2


source


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 [].

+1


source


This worked for me:

<field name="reference" attrs="{'invisible' :[('line_ids', '!=', [])]}"/>

      

0


source


Try this method. This worked for me

<field name="reference" attrs="{'invisible': [('line_ids', '=', [(6, False, [])])]}" />

      

0


source







All Articles