【发布时间】:2015-04-06 16:16:47
【问题描述】:
如何使用 OnChange 检索 Many2one 字段的值?
学生应注册在一个标准和一个组...该标准有多个组 所以我希望当我更改字段标准时.. 组字段应该使用该标准中的组进行更新
当我尝试这样做时,它给了我一个错误
'Expected singleton: fci.standard.groups(3, 4, 5, 6)'
我正在尝试当我更改标准字段时,组字段将更新为仅选择此标准中的组
这是我的字段
'standard_id': fields.many2one('fci.standard', string='Standard', required=True),
'group_id': fields.many2one('fci.standard.groups', string='Standard Group'),
这是我的功能
def on_change_standard(self, cr, uid, ids, standard_id, context=None):
val = {}
if not standard_id:
return {}
student_obj = self.pool.get('fci.standard')
student_data = student_obj.browse(cr, uid, standard_id, context=context)
val.update({'group_id': student_data.groups_ids.id})
return {'value': val}
这是我的 xml
<field name="standard_id" on_change="on_change_standard(standard_id)" widget="selection"/>
<field name="group_id" widget="selection"/>
【问题讨论】:
-
您可以使用域来执行此操作。但是你需要删除widget="selection"。动态域不能与 widget="selection" 一起使用。选择小部件只会忽略动态域。
标签: python xml openerp onchange odoo