Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
11 Respostas
11268 Visualizações

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

Avatar
Cancelar
Melhor resposta

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
Cancelar

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

Melhor resposta

Examples:

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

or

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

Avatar
Cancelar

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

Autor Melhor resposta

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

Avatar
Cancelar
Melhor resposta

hey try this

<field name="my_field" attrs="{'column_invisible': [('my_other_field','=',False)]}" />
Avatar
Cancelar
Melhor resposta

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
Cancelar