Odoo Help


How to set a field invisible dynamically

Voathnak Lim
on 5/30/13, 8:26 AM 5,276 views

Hello, what I need is to set a certain field invisible or visible depending on a many2one field selection. The problem is i cant do it in xml, I need to do it in python code, using the on_change method that is called whenever my many2one field changes. What i dont know how to do, is to set the field to invisible or visible?

On the other hand i could do it in xml, but i cant figure out how to make it work. This is my current code in xml:


<field name="currency_it" string="Currency" />
<field name="amount" attrs="{'invisible':[('currency_id','!=',company_id.currency_id)]}"/>

But it just doesnt do anything. Help please!!! Any solution would do. thanks

An idea is to create a boolean field and set that boolean field True based on your desired condition. And use that boolean field in XML to dynamically visible and invisible fields.

Have a look in code: http://learnopenerp.blogspot.com/2016/10/how-to-visible-and-invisible-fields-in.html

on 4/26/18, 6:08 AM

Francesco OpenCode

--Francesco OpenCode--

| 6 8 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 5/30/13, 11:23 AM

A solution is to create a related field (for example called related_currency_id) andset attrs on this one. Here an example:


related_currency_id = fields.related('company_id', 'currency_id', type='many2one',relation='res.currency', string='Currency'),


<field name="currency_id" />
<field name="related_currency_id" />
<field name="amount" attrs="{'invisible':[('currency_id','!=',related_currency_id)]}"/>
On 5/30/13, 9:26 AM
<field name="currency_id" string="Currency" />
<field name="amount" attrs="{'invisible':[('currency_id','!=',company_id.currency_id)]}"/>

Perhaps, you need to rename field "currency_it" to "currency_id"?

On 5/30/13, 8:35 AM

I think your currency field name is currency_it

so used this

> <field name="amount"
> attrs="{'invisible':[('currency_it','!=',company_id.currency_id)]}"/>

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

Question tools

0 follower(s)


Asked: 5/30/13, 8:26 AM
Seen: 5276 times
Last updated: 3/16/15, 8:10 AM