تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
10 الردود
12939 أدوات العرض

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?

الكاتب

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",

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

أفضل إجابة

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?

This always gets the result in English.

أفضل إجابة

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>

الصورة الرمزية
إهمال

This gets the translated result.

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.

أفضل إجابة

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)
الصورة الرمزية
إهمال