Odoo Help


3 Answers
vim24 New Zealand
5/16/13, 8:44 PM

Having just scoured the internet looking for an answer to a similar problem myself I can tell you how I finally got something similar working:

Instinct told me to try the


approach too. But, I believe attrs don't work to stop the column name itself from appearing in a tree view (works only on the values of each row).

Instead, you need to overwrite the fields_view_get method from within your res_partner python code, which will allow you to change the viability of each column by checking the context. In my case I was looking at Supplier vs Customer invoices, so I checked for the context 'type' being 'out_invoice'/'in_invoice'. In your case I believe customers vs suppliers are given a context value, something like "default_customer" and "default_supplier".

Anyway, in the end you want to remove the attrs element from you xml view and then add something like this to the python code:

  from lxml import etree

  def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):

    if context is None:
        context = {}

    res = super(res_partner,self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)

    doc = etree.XML(res['arch'])

    if view_type == 'tree':
        if context.get('default_customer', '0') in ('1'):
            for node in doc.xpath("//field[@name='n_supplier']"):
        if context.get('default_supplier', '0') in ('1'):
            for node in doc.xpath("//field[@name='n_client']"):

        res['arch'] = etree.tostring(doc)
    return res

I can't guarantee this will work straight off as I havn't tested it for your case, you might need to tweak some values above. Nor can I guarantee this is the best way to achieve this. But I can say very similar code is working perfectly for me in my situation.

Hope that helps :)

Tintu Mon India
4/11/16, 9:23 AM

For other view like "form view" it works fine


If you use this attrs in Tree view it just hide the data/content which shown in that column. Not the complete column.

So I just tried using this instead of above code:

invisible = "context.get('customer') != True"

And it helped me to hide the complete column from Tree view.

Gustavo Colombia
1/17/14, 9:50 AM

Using the attrs XML attributes to set the invisible attribute of an element 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>

Source: http://vitraining.com/show-hide-columns-in-openerp-tree-view-xml/

Ask a Question
Keep Informed
0 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now