6

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.

priyankarani
  • 91
  • 1
  • 2
  • 5
  • I see you're new to SO. If you feel an answer solved the problem, please mark it as 'accepted' by clicking the green check mark. This helps keep the focus on older SO which still don't have answers. – Alessandro Ruffolo Oct 05 '15 at 08:59

6 Answers6

16

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

  • 1
    The empty list `('something_ids', '!=', [])` works for required by Many2many in Odoo 13, False or tuple don't seem to. – LuH Mar 23 '20 at 08:35
6

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

2

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

Alessandro Ruffolo
  • 1,575
  • 1
  • 16
  • 34
0

This worked for me :

<field name="reference" attrs="{'invisible' :[('line_ids', '!=', [])]}"/>
  • I would double check that, in the case of Odoo 10, 9 and 7 you created a condition that the field will be invisible whenever line_ids is NOT empty and in the case of Odoo 8, you created a condition that will always be True and therefore the field will never be visible. – Paulius Stundžia Apr 28 '17 at 21:08
0

Try this method. This one worked for me

<field name="reference" attrs="{'invisible': [('line_ids', '=', [(6, False, [])])]}" />
Akhil Mathew
  • 1,571
  • 3
  • 34
  • 69
0

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

It works for me in openerp7

Tue Nguyen
  • 11
  • 1