Skip to Content
Menu
This question has been flagged
11 Replies
10495 Views

I would like to hide a field in a tree view depending on a condition on other field

Avatar
Discard
Best Answer

This code is used to hide fields in one2many(tree)

<field name="my_field" attrs="{'column_invisible': [('parent.field_name','=',False)]}" />


this type of code only works gives 'parent' in condition



Avatar
Discard

is it possible to work with out parent ?

my column on same line not in parent

no.This type of code works only with parent

Best Answer

Examples:

<field name="my_field" invisible="context.get('default_my_other', False)" />

or

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

Avatar
Discard

I don't think this will make the field in tree view invisible.

it will just make the field's values Invisible... but the column is still there.

I completely agree

Author Best Answer

Thanks to all of you, especially to Zbik for his 2 links, with which I was able to achieve my goal.   

Avatar
Discard
Best Answer

hey try this

<field name="my_field" attrs="{'column_invisible': [('my_other_field','=',False)]}" />
Avatar
Discard
Best Answer

One solution to completely remove a column from a basic tree view.

    def fields_view_get(self, view_id=None, view_type='tree', toolbar=False, submenu=False):
result = super(ThisModel, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
if not self.env.context.get('show_the_column', False) and view_type == 'tree':
doc = etree.fromstring(result['arch'])
for field in doc.xpath('//field[@name="name_of_conditional_column"]'):
field.set('invisible', '1')
modifiers = json.loads(field.get('modifiers', '{}'))
modifiers['tree_invisible'] = True
modifiers['column_invisible'] = True
field.set('modifiers', json.dumps(modifiers))
result['arch'] = etree.tostring(doc)
return result


Avatar
Discard