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

Hide product field depending on category

By
Alex
on 4/24/13, 1:21 PM 1,625 views

I would like to hide several fields when the product belongs to a certain category. I have tried this in my xml view:

attrs="{'invisible': [('categ_id', '!=', 'mycategory')]}"

But it hides the fields regardless of category name. I think there should be another field name related to category name.

Any help?

0

patrick

--patrick--
1958
| 5 4 7
Baarn, Netherlands
--patrick--
patrick
On 4/24/13, 1:26 PM

You are trying to compare an int (categ_id) with a string ('mycategory'). Because the int is always different from the string, it will hide the field.

Try to use the ID of 'mycategory', or better, get the name of categ_id (categ_id.name or so).

If i write attrs="{'invisible': [('categ_id.name', '!=', 'NAME_OF_CATEGORY')]}" I get the next error: Uncaught Error: Unknown field categ_id.name in domain [["categ_id.name","!=","example"]]

Alex
on 4/25/13, 7:16 AM
0
Dharmesh Rathod
On 4/25/13, 5:28 AM

Hi,

You can use following ways:

(1) attrs="{'invisible': [('categ_id', '!=', ID)]}"

(2) attrs="{'invisible': [('categ_id.name', '!=', NAME_OF_CATEGORY)]}"

Email : info@acespritech.com
Skype : acespritech
Blog : acespritechblog.wordpress.com/

If i write attrs="{'invisible': [('categ_id.name', '!=', 'NAME_OF_CATEGORY')]}" I get the next error: Uncaught Error: Unknown field categ_id.name in domain [["categ_id.name","!=","example"]]

Alex
on 4/25/13, 7:16 AM

Use this attrs="{'invisible': [('categ_id', '=', ID)]}"

Dharmesh Rathod
on 4/25/13, 7:55 AM

If I have no chance, I will use that, but ID can change and the name couldn't. I would prefer to use the name. Thank you anyway, all comments are appreciated.

Alex
on 4/25/13, 8:05 AM

ID will never change unless user delete record. User can change name from UI.

Dharmesh Rathod
on 4/25/13, 8:15 AM

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: 4/24/13, 1:21 PM
Seen: 1625 times
Last updated: 3/16/15, 8:10 AM