odoo 中如何获取一个selection字段的值以及显示值

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

我们都知道self.type输出的是“a”或者“b”,但是在很多时候我们要获取到“吃”或者“喝”,比如在Report里面输出type的值,此时该怎么办呢?

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

在这里插入图片描述
里面的self可根据是否是当前模型来判断。

这一行代码就可以轻松实现,并且在py和xml都可以使用该行代码

猜你喜欢

转载自blog.csdn.net/weixin_42464956/article/details/108602139