首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >更改选择字段odoo 8

更改选择字段odoo 8
EN

Stack Overflow用户
提问于 2016-08-23 09:14:01
回答 2查看 2.6K关注 0票数 1

我正在尝试根据模型中的其他字段生成不同的选择。我在Odoo 8中工作,代码如下:

我的模型:(test.py)

代码语言:javascript
运行
复制
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)

代码语言:javascript
运行
复制
<field name="type" widget="selection"/>

但我在选择字段中看不到任何值。

请帮帮忙。

谢谢,

EN

回答 2

Stack Overflow用户

发布于 2016-08-23 13:31:11

代码语言:javascript
运行
复制
@api.model
def _get_selection(self):
    #DO SOMETHING
    return choise
type = fields.Selection(selection=_get_selection, string='Type')
票数 1
EN

Stack Overflow用户

发布于 2016-08-23 14:06:27

这是Odoo 8中'account.invoice‘的一个例子:

代码语言:javascript
运行
复制
@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')

这可以帮助你解决这个问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39090888

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档