Odoo Help

2

1
10 Answers
2
Avatar

Nehal India

--Nehal--

2131
| 6 2 10
Ahmadabad, India
--Nehal--
Nehal India
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
2 Comments
Anton Chepurov Estonia
11/28/14, 5:01 AM

How do you format your code snippet as code?

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

This always gets the result in English.

1
Anton Chepurov Estonia
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:

<t>

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

</t>

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

<t>

    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')

</t>

2 Comments
Jairo Llopis Spain
10/27/15, 4:57 AM

This gets the translated result.

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

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.

0
Beto Martinez Colombia
6/21/19, 3:37 PM

I know it a little late but you can use this method

category_id = self.browse(cr, uid, id)
category = dict(category_id.fields_get(["sec_catoegory"],['selection'])['sec_catoegory']["selection"]).get(category_id.sec_catoegory)
Ask a Question
Keep Informed
0 follower(s)
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.

Register
Odoo Training Center

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

Test it now