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.

1

How to compare on many2one field inside Views?

By
mike
on 6/7/13, 6:16 PM 2,469 views

I have a many2one field state_id from res.country.state. Based on the state I want the view to change with

attrs="{'invisible':[('state_id', '=', '39')]}

and

colors="red:state_id=='39'"

Both cause errors. So I try state_id equals 'Pennsylvania' and more errors. Then since the data is passed via JSON as an object I try state_id.id and more errors. So then I try state_id[0] with same result. There must be a way to use conditionals in views with many2one fields like this although I could not find examples in the source code of various addons. Does anybody know the way to handle this?

3

Sandeep

--Sandeep--
6083
| 6 5 8
Delhi, India
--Sandeep--
Python OpenERP Developer http://in.linkedin.com/pub/sandeep-rana/3b/a16/786/
Sandeep
On 6/8/13, 8:11 AM

Hi as i don't want you to use state_id or many2one field like that

you my suggestion is that you should use state_id.name and give the 'name' that which country you want.

or if you still want state_id then just do like below

  attrs="{'invisible':[('state_id.id', '=', 39)]}

  and

  colors="red:state_id.id==39"

but you should use name because in this case you can change the name of country in user interface while you can not change ID so it should be like

  attrs="{'invisible':[('state_id.name', '=','Newyork')]}

  and

  colors="red:state_id.name=='Newyork'"

Thanks
Sandeep

I got this: Error: QWeb2 - template['ListView.rows']: Runtime Error: Error: QWeb2 - template['ListView.row']: Runtime Error: Error: AttributeError: object has no attribute 'name'

mike
on 6/10/13, 11:12 AM

i'm also same error

Rajkumar
on 1/8/16, 7:28 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: 6/7/13, 6:16 PM
Seen: 2469 times
Last updated: 3/16/15, 8:10 AM