Odoo Help


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.


Selection Field : Label

Abhishek H Menon
on 1/31/14, 1:38 AM 1,151 views

Is there any method to fetch the label of a selection field from its value?

For eg:-

'type': fields.selection([('product','Stockable Product'),('service','Service Product'), ('consu','Consumable Product')],'Type')

if we wish to fetch a product type like product.type if its value is 'service' we want to get its label as 'Service Product', is there any way to get the label in python or in openerp ?

One solution for this is to make a dictionary like { 'product':'Stockable Product','service':'Service Product', 'consu':'Consumable Product'}. According to the conditions we can fetch the key values from the dictionary

on 1/31/14, 6:40 AM

Ok thanks. But is there any method to fetch it directly from the field description itself?

Abhishek H Menon
on 1/31/14, 6:45 AM


| 4 3 5
Hyderabad, India

On 10/28/15, 1:15 AM


You can try this with your object and field 'type':

dict(self.pool.get('YOUR.OBJECT').fields_get(cr, uid, allfields=['FIELD'], context=context)['FIELD]['selection'])['KEY']

Hope it helps!    

thanks, works well :)

on 12/30/15, 7:05 AM

this self.fields_get(cr, uid, ["field"], context=context) Return the field definition. I hope help you.

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)


Asked: 1/31/14, 1:38 AM
Seen: 1151 times
Last updated: 10/28/15, 1:15 AM