How to check if one2many field is empty in openerp xml views

12.3k views Asked by At

I'm trying to make some field invisible if another field ( which is one2many ) has no value ( is empty).

I'm trying something like

<field name="reference" invisible="{'line_ids', '=', False}"/>

Also tried

<field name="reference" invisible="{'line_ids', 'in', []}"/>

And finally

<field name="reference" invisible="{'line_ids', '=', None}"/>

Note: line_ids is one2many field

But did not work. Somebody please suggest if some possible way to do this.

6

There are 6 answers

1
Emipro Technologies Pvt. Ltd. On

Try following,

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

This is the behaviour of attrs in odoo, version by version it's differ.

enter image description here

0
Tue Nguyen On

[('line_ids', '=', [[6, False, []]])]

It works for me in openerp7

1
Alessandro Ruffolo On

I have the same issue. I tried with Emipro's solutions, but doesn't work (but you still must use "attrs" instead of invisible).

Also, I tried with

[('line_ids', '=', [(0, 0, [])])]

and

[('line_ids', '=', [(6, False, [])])]

but nothing worked.

In the end, I ended up creating a boolean computed field

self.line_count = len(self.line_ids) > 0

and it works with the simpler condition

[('line_count', '=', False)]

if anybody would suggest the correct solution....

1
jani435 On

This worked for me :

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

Try this method. This one worked for me

<field name="reference" attrs="{'invisible': [('line_ids', '=', [(6, False, [])])]}" />
0
Paulius Stundžia On

For a One2many field in Odoo 10, I have just tested myself and an empty list works, as in:

attrs="{'invisible': [('item_ids', '=', [])]}"

I have heard from other people that the above works for Odoo 9 as well. For Odoo 8 I've also used:

attrs="{'invisible': [('item_ids', '=', [(6, False, [])])]}"

...with success. If any of these are not working for you and your respective version, try updating your source. Also, for Odoo 7 the empty list way should work (but I haven't tried it myself). It's kinda weird how they went from [] to [(6, False, [])])] and then back to [].