How to get the value and display value of a selection field in odoo

type= fields.Selection([('a', '吃'), ('b', '喝')], string='类型')

We all know that self.type outputs "a" or "b", but in many cases we need to get "eat" or "drink", such as outputting the value of type in Report. What should we do at this time?

type= dict(self.fields_get(allfields=['type'])['type']['selection'])[self.type]

Insert picture description here
The self inside can be judged according to whether it is the current model.

This line of code can be easily implemented, and it can be used in both py and xml

Guess you like

Origin blog.csdn.net/weixin_42464956/article/details/108602139