Odoo Help


Selection Field : Label

Abhishek H Menon
on 1/31/14, 1:38 AM 2,130 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
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.

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


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