Hide fields on tree depending on another field

Hi,

I was wondering how to hide or show a field depending on the value of other field in the tree view.

The field type has many values, but only with the value ‘fuel’ need to hide/show the other field.

I tried with
states={
‘readonly’: _states[‘readonly’],
‘invisible’: Bool(Not(Eval(‘type’)==‘fuel’)),
‘required’: Bool(Eval(‘type’)==‘fuel’),
},

and with

@classmethod
def view_attributes(cls):
    return [
        ('/tree/field[@name="idp_type"]', 'tree_invisible',
            Bool(Not(Eval('type')=='fuel'))),

But I’m not sure how it can be do. Thanks in advance!

Hiding the field, as in hiding the column might not be the proper solution, as there are many records being displayed.

You could instead use a function field to display or not content for that field based on your logic.

Thanks for your help, did you know where can I find a example about it? Thanks!

For me, the best is to set invisible states to True with a PYSON statement like in your first attempt.
As @fmorato said, you can not hide the all column because it depends on each row.

Well, the full code is like these:

type = fields.Selection([('fuel','Fuel'),  ('other','Other')], "IDP Type", 
    states={
        ‘readonly’: _states[‘readonly’],
        ‘invisible’: Bool(Not(Eval(‘type’)==‘fuel’)),
        ‘required’: Bool(Eval(‘type’)==‘fuel’),
        }, depends=['type']
   )

idp_type = fields.Selection([('super','Super'),  ('diesel','Diesel')], "IDP Type", 
    states={
        ‘readonly’: _states[‘readonly’],
        ‘invisible’: Bool(Not(Eval(‘type’)==‘fuel’)),
        ‘required’: Bool(Eval(‘type’)==‘fuel’),
        }, depends=['type']
    )

The fields are displayed on a tree view and I want to hide ‘idp_field’ if the ‘type’ is not ‘fuel’. With the form view it works fine, can show/hide the field, but with tree view not.

I understain your point, thank you, I will try another solution for the case.

If it works within the form view, it will work with the tree view.
But you have to realize that a column can not disappear for a row and still be present for other rows.
So instead of hiding the column what happens is that its content won’t be displayed.