Show / Hide Columns in OpenERP Tree View XML

Using the attrs XML attributes to set the invisible attribute of an element (as documented here) is not working. In fact, this attrs will only show or hide the content of the tree view, not the entire column.

After searching for some solutions from google, i found this one is working. As an example, i add two new fields on invoice model (called ref_partner_id and sales_inv) and it will shows on the invoice tree view only if the type is out_invoice (supplier invoice):

<field name=”ref_partner_id” string=”Customer (name)” invisible=”context.get(‘type’) == ‘out_invoice’ “/>

<field name=”sales_inv”  invisible=”context.get(‘type’) == ‘out_invoice’ “/>

This will work because we got the context variable that inform us the type of invoices currently being displayed on the tree. This comes from the account module (account_invoice_view.xml), for example on the action_invoice_tree2:

<record id=”action_invoice_tree2″ model=”ir.actions.act_window”>
<field name=”name”>Supplier Invoices</field>
<field name=”res_model”>account.invoice</field>
<field name=”view_type”>form</field>
<field name=”view_mode”>tree,form,calendar,graph</field>
<field eval=”False” name=”view_id”/>
<field name=”domain”>[(‘type’,’=’,’in_invoice’)]</field>
    <field name=”context”>{‘default_type’: ‘in_invoice’, ‘type’: ‘in_invoice’, ‘journal_type’: ‘purchase’}</field>

So here we go, clicking the Supplier Invoice will give the tree like this:

Screen shot 2013-02-22 at 11.06.36 AM

and Clicking the Customer Invoice will give this:


Screen shot 2013-02-22 at 11.05.06 AM




[box type=”info”]

Please contact us for further information


Address: Grand Surapati Core Blok C-16 Jl PHH Mustofa 136 Bandung, Indonesia

Telephone : +62 (22) 8724 1394

Fax : +62 (22) 8724 1394

Mobile Phone Number : +62 813 2037 9277

Email: akhmad.daniel[at] or info[at]