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

fields.related and fields.selection

By
Andrew
on 12/15/14, 10:59 AM 1,261 views

Hello.

It is possible to use fields.related which points to a char field and to show values as selection? I would like to do something like this:

'name': fields.char('Name', required=True, )

'related': fields.related('name', ,'related', type="selection", required=False, readonly=False, string='Related', store=True),

But this code is broken.

In other words - i would like to extract values from field 'name' and display them as selection.

For your requirement, you could try using Computational field and provide output as SELECTION.

Atchuthan - Technical Consultant, Sodexis Inc
on 12/16/14, 2:36 AM
2

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

Bole
On 12/15/14, 12:00 PM

QUICK answer is NO, NOT POSSIBLE!
explanation... 
field related is (can only be) of type the original field  is.. so if you make a relateion to a char field it can only be of type=char...
if you want selection, then you can make field related to some field selection in other model... 

Or if you need a field selection, you could make a dynamiy selection form a private method...

hope it helps.. 
 

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 12/16/14, 3:15 AM

I haven't tried it myself, but I think it is possible.  The trick lies in the fact that for a selection field is actually a char field anyway.  There are some limitation such as selection field only have a fix max length (which unfortunately I couldn't remember on top of my head).  Another trick is that you can supply a function to supply the selection list.  So, I presume that if the values in you char fields are not longer than the max length and you can create a function that returns [('name 1', 'name 1'), ('name 2', 'name 2'), ....] you may be able to make a related field as a selection field instead of char field.

It would be hard to me to guess what is the advantage of doing this though.  One reason why I would ask that is because the related field should be displayed readonly unless if the write mechanism is developed specifically to handle that.

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

2 follower(s)

Stats

Asked: 12/15/14, 10:59 AM
Seen: 1261 times
Last updated: 3/16/15, 8:10 AM