This question has been flagged
3 Replies
12803 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

Avatar
Discard

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

Best Answer

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)]}"/>
Avatar
Discard
Best Answer
<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"?

Avatar
Discard
Best Answer

I think your currency field name is currency_it

so used this

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