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

How to set a field invisible dynamically

By
voathnak lim
on 5/30/13, 8:26 AM 3,336 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

--Francesco OpenCode--
3608
| 5 7 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:

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)]}"/>

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

0 follower(s)

Stats

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