我正在尝试根据模型中的其他字段生成不同的选择。我在Odoo 8中工作,代码如下:
我的模型:(test.py)
type = fields.Selection(selection='_get_selection', string='Type')
@api.onchange('role_name')
def _get_selection(self):
choise = []
if self.role_name == 'primary':
choise.append(('unit','Unit Case'))
if self.role_name == 'reserve':
choise.append(('res','Reserve Case'))
return choise
视图:(template.xml)
<field name="type" widget="selection"/>
但我在选择字段中看不到任何值。
请帮帮忙。
谢谢,
发布于 2016-08-23 13:31:11
@api.model
def _get_selection(self):
#DO SOMETHING
return choise
type = fields.Selection(selection=_get_selection, string='Type')
发布于 2016-08-23 14:06:27
这是Odoo 8中'account.invoice‘的一个例子:
@api.model
def _get_reference_type(self):
return [('none', _('Free Reference'))]
reference_type = fields.Selection('_get_reference_type', string='Payment Reference',
required=True, readonly=True, states={'draft': [('readonly', False)]},
default='none')
这可以帮助你解决这个问题。
https://stackoverflow.com/questions/39090888
复制相似问题