如何获取选择字段的字符串?
How to get string of selection field?
我的模块中有以下 selection 字段 我想获取 selection 字段的字符串值。假设用户 select 'o'
我想打印 O - Original
请提供更好的解决方案。
type = fields.Selection([
('o', 'O - Original'),
('a', 'A - Amended')],
string="Is this an Original Invoice or Amended Invoice ?"
我有这个解决方案
def get_string_value_of_selection():
if self.type == 'o':
value = "O - Original",
if self.type == 'a':
value = "A - Amended"
print "value = ",value
输出
如果用户 select o
value = O - Original
可以按如下方式存档。在 odoo 9 中工作,10 在 8 中未尝试
print dict(self._fields['type'].selection).get(self.type)
如果用户 select o
输出
O - 原创
我的模块中有以下 selection 字段 我想获取 selection 字段的字符串值。假设用户 select 'o'
我想打印 O - Original
请提供更好的解决方案。
type = fields.Selection([
('o', 'O - Original'),
('a', 'A - Amended')],
string="Is this an Original Invoice or Amended Invoice ?"
我有这个解决方案
def get_string_value_of_selection():
if self.type == 'o':
value = "O - Original",
if self.type == 'a':
value = "A - Amended"
print "value = ",value
输出
如果用户 select o
value = O - Original
可以按如下方式存档。在 odoo 9 中工作,10 在 8 中未尝试
print dict(self._fields['type'].selection).get(self.type)
如果用户 select o
输出 O - 原创