Odoo Help


Using xml_id for attrs

valentin chemiere
on 8/6/13, 12:35 PM 2,357 views


I want to hide some columns in sale order form depends to product selected.
I think i can use the product's xml_id like this :
<field name="myfield" attrs="{'invisible': [('product_id', '!=', ref('product.my_product'))]}"/>

but i have an error :

NameError: name 'ref' is not defined

What is wrong with my attrs? There is another method to hide a field when a particular product is selected?


Sudhir Arya (SA)
On 2/15/17, 2:09 PM

Hi Valentine,

By overriding fields_view_get you can do so.

Reference: fields_view_get example

Marvin Taboada
On 9/9/15, 11:48 PM

Sorry valentin, you can't do this.

`ref()` can only be used inside `eval` XML attributes (which is evaluated by Odoo's `safe_eval` module) as in the following example:


If your product is well known (you're already referring it by their External-ID in your example), you may try referring other field with a known value, like the product `code` ("Internal Reference") or  `ean13` ("EAN13 Barcode"):

<field name="myfield" attrs="{'invisible': [('product_id.code', '!=', 'SOME.PRODUCT.CODE')]}"/>


Aleksander Nøkland
On 2/15/17, 9:38 AM

In Odoo10 you can do the following:

<field name="myfield" attrs="{'invisible': [('product_id','!=', %(other_module.xml_id)d)]}"/>

Source: https://answers.launchpad.net/openobject-server/+question/181987

Whoops. Didn't read the entire question.

You can still use this for xml-id's in attrs at least...

Norges Eiendomsfinans AS, Aleksander Nøkland
on 2/15/17, 9:40 AM

I think you can't hide columns in tree view depending on some choices in the runtime. This is straightforward in form views and could be achieved using attrs tag.

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: 8/6/13, 12:35 PM
Seen: 2357 times
Last updated: 10/11/17, 10:18 AM