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.

3

Using xml_id for attrs

By
valentin chemiere
on 8/6/13, 12:35 PM 1,514 views

Hello,

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?

Thanks.

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

https://github.com/odoo/odoo/blob/8.0/addons/account/account_bank_view.xml#L42 

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

Regards.

0

Tarek Mohamed Ibrahim

--Tarek Mohamed Ibrahim--
896
| 5 3 7
Gîza, Egypt
--Tarek Mohamed Ibrahim--

I am an old VFP developer on ERP

I have moved to 2p since Nov-2014 and started developing with Python on Odoo.

https://www.linkedin.com/profile/public-profile-settings?trk=prof-edit-edit-public_profile

tibrahim@2p.com.sa

Tarek Mohamed Ibrahim
On 9/9/15, 2:54 PM

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.



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: 8/6/13, 12:35 PM
Seen: 1514 times
Last updated: 2/10/16, 2:25 PM