下面是我的视图 xml 和模型类。我有一个表格来添加记录,它工作正常。但我需要为那个子孩子的 onchange 事件设置值。我也从文档中引用了这个链接。
这是我的模块GIT HUB REPO的全部代码:
<field name='selected_tea_workers_line_ids' nolabel='1'>
<tree string='List' readonly='1'>
<field name='tea_line_worker_id' invisible="0" />
<field name='worker_id' />
<field name='is_selected' />
</tree>
</field>
def on_change_division(self, cr, uid, ids, bpl_division_id):
v = {}
if bpl_division_id:
work_offer = self.pool.get('bpl.work.offer').browse(cr, uid, 2)
v['selected_tea_workers_line_ids'] = work_offer.selected_tea_workers_line_ids
if work_offer.selected_tea_workers_line_ids:
for record_item in work_offer.selected_tea_workers_line_ids:
v['tea_line_worker_id'] = record_item.selected_tea_workers_line_ids.tea_line_worker_id
v['worker_id'] = record_item.selected_tea_workers_line_ids.worker_id
v['is_selected'] = record_item.selected_tea_workers_line_ids.is_selected
return {'value':v}
想法是这样的:如果我选择公司 -> 部门 -> 则需要加载与该部门相关的所有工作人员(作为列表。他们有他们的姓名和工作)。
下面,我添加了示例图片
得到了答案
def on_change_division(self, cr, uid, ids, division_id):
v = {}
list_data = []
if division_id:
worker_ids = self.pool.get('bpl.worker').search(cr, uid, [('bpl_division_id', '=', division_id)])
for record in self.pool.get('bpl.worker').browse(cr, uid, worker_ids):
list_data.append({'worker_id': record.id})
v['selected_tea_workers_line_ids'] = list_data
return {'value':v}
积分需要去user1576199