I would like to hide a field in a tree view depending on a condition on other field
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
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
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
Examples:
<field name="my_field" invisible="context.get('default_my_other', False)" />
or
<field name="my_field" attrs="{'invisible': [('field_my_other','=',False)]}" />
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
See this JKE-be comment: https://github.com/odoo/odoo/issues/13751
or this https://www.odoo.com/forum/help-1/question/hide-column-tree-view-31040#answer_31060
Thanks to all of you, especially to Zbik for his 2 links, with which I was able to achieve my goal.
hey try this
<field name="my_field" attrs="{'column_invisible': [('my_other_field','=',False)]}" />
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
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
Aanmelden
Reference links:
1- http://learnopenerp.blogspot.com/2016/10/how-to-visible-and-invisible-fields-in.html
2- http://learnopenerp.blogspot.com/2018/01/get-parent-form-value-in-one2many-form.html
Hope this will helps you and others.