Odoo Help


browse the value from a selection field in the class

Praveen Upadhyaya
on 4/25/14, 5:10 AM 4,833 views

category = self.browse(cr, uid, id).sec_catoegory

This is returning the id not the value in the field

Is sec_catoegory field is of many2one type?

on 4/25/14, 5:29 AM

no sec_catoegory is a selection field in the form that get list from a other class 'sec_catog':fields.selection(_select_category, type="char", store=True, method=True, string="Select Category",

Praveen Upadhyaya
on 4/25/14, 6:16 AM

categ = self.browse(cr, uid, ids[0]).sec_catoegory categ_val = dict(self._columns['sec_catoegory'].selection).get(categ) print categ_val

on 4/28/14, 9:01 AM


| 5 2 8
Ahmadabad, India
On 4/25/14, 7:03 AM

Try to get value of the selection field ::

categ = self.browse(cr, uid, ids[0]).sec_catoegory
categ_val = dict(self._columns['sec_catoegory'].selection).get(categ)
print categ_val

How do you format your code snippet as code?

Anton Chepurov
on 11/28/14, 5:01 AM

This always gets the result in English.

Jairo Llopis
on 10/27/15, 4:57 AM
Anton Chepurov
On 11/28/14, 4:28 AM

If you also want the value to be translated:

Add this method to browse_record class in server/openerp/osv/orm.py:


    def sel_val(self, field):
        if field not in self._data.setdefault('sel_vals', {}):
            selection = dict(self.pool.get(self._table_name).fields_get(self._cr, self._uid, [field], context=self._context)[field]['selection'])
            self._data['sel_vals'][field] = selection
        return self._data['sel_vals'][field][getattr(self, field)]


And use it like this:


    self.browse(cr, uid, id).sel_val('sec_catoegory')


Don't forget to specify the right language in the context of browse() if you want your selection values to be translated:


    self.browse(cr, uid, id, context={'lang': some_partner.lang}).sel_val('sec_catoegory')

    self.browse(cr, uid, id, context={'lang': 'ru_RU'}).sel_val('sec_catoegory')


This gets the translated result.

Jairo Llopis
on 10/27/15, 4:57 AM

Any way to get something similar without changing the source code? I'd like to get the value in a specific language like you do.

Mathieu Laflamme
on 12/10/15, 12:44 PM

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 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: 4/25/14, 5:10 AM
Seen: 4833 times
Last updated: 12/10/15, 12:48 PM