Odoo Help

0

How to set a field invisible dynamically

By
Voathnak Lim
on 5/30/13, 8:26 AM 4,604 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:

Code:

<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

1
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:

PYTHON CODE

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

XML CODE

<field name="currency_id" />
<field name="related_currency_id" />
<field name="amount" attrs="{'invisible':[('currency_id','!=',related_currency_id)]}"/>
1
Alexander
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"?

0
jamesbale
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.

Register

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)

Stats

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