Odoo Help

Welcome!

This community 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.

0

Hide tree view column using a context value (odoo9)

By
Adnier Rosello
on 11/1/16, 5:26 PM 157 views

HI, 

I know that is not possible hide a field in tree view with attrs={"invisible":[('field_name','=',True)]}, and it is possible using: invisible attribute like this: invisible="context.get('field_name',False)", but I want to know how I can pass a field value through context from model to view, Ex:

model.py

admin_user = fields.Boolean(string="Name", default=True)


view.xml

<tree>

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

</tree>


Any example for this question?,

Thanks

1

Nilmar Shereef

--Nilmar Shereef--
811
| 4 3 7
Calicut, India
--Nilmar Shereef--

Python Developer. Android Developer. .Net Developer

Nilmar Shereef
On 11/2/16, 6:08 AM

You can hide your field according to your conditions via following steps.
Note : You want to import

from lxml import etree

 In your Python code:


in your xml add invisible=0 with your field in xml:


 <tree>      

    < field name="field_name" invisible="0"/>   

</tree>


I think it may hep you

0
Sarga
On 11/2/16, 10:43 AM

Hi,

you can update the context by calling super of fields_get function from the model of tree view.Can update context by 

context.update({'admin_user':False}) and pass the updated context in super

Hi sarga,

maybe do you have any example by this way, because I don't know how to use this function (fields_get), Thanks.

Adnier Rosello
on 11/10/16, 1:41 PM

Hi,

I just show you how I just used fields_get in sale order model to update context.

def fields_get(self,cr,user,all fields=None,context=None,write_access=True,attributes=None):

context_copy=context.copy()

context_copy.update({'admin_user':False})

return super(so,self).fields_get(cr,user,allfields,context_copy, write_access,attributes)

Sarga
on 11/11/16, 10:41 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/1/16, 5:26 PM
Seen: 157 times
Last updated: 11/2/16, 10:43 AM