【发布时间】:2013-04-30 10:04:09
【问题描述】:
我需要加载工人的津贴和扣除额。
津贴 2 种固定和可变。
扣除也有 3 种固定、可变和特殊。
那么我的班级有这样的关系
津贴 one2many 固定
津贴 one2many 变量
扣one2many固定
扣除 one2many 变量
扣one2many特价
我的最后一个要求是将这些扣除额和津贴加载到两个''标签中
然后我为 onchange_worker 编写了一个方法。但它没有用 & 希望你能帮助我解决这个问题
谢谢
(最初我为固定津贴编写代码)
在我的课堂上发挥作用
def on_change_worker(self, cr, uid, ids, worker_id):
fixed_v = {}
fixed_list_v = {}
fixed_list = []
fixed_list_data = []
if worker_id:
ind_allowance_id = self.pool.get('bpl.allowance.individual.data').search(cr, uid, [('worker_id', '=', worker_id)])
ind_allowance_obj = self.pool.get('bpl.allowance.individual.data').browse(cr, uid, ind_allowance_id)[0]
for allowance_record in ind_allowance_obj.fixed_allowance_ids:
fixed_list.append({'allowance_id':allowance_record.allowance_id.id, 'allowance_name': allowance_record.allowance_name.id })
fixed_v['allowance_ids'] = fixed_list
fixed_list_data.append(fixed_v)
fixed_list_v['fixed_allowance_ids'] = fixed_list_data
return {'value':fixed_list_v}
view.xml
<form string='bpl_worker_summary' version='7.0'>
<sheet>
<group>
<group>
<field name='bpl_company_id' readonly="1" />
<field name='bpl_estate_id' />
<field name='worker_id' on_change="on_change_worker(worker_id)" />
</group>
</group>
<div name="Allowances"></div>
<separator string="Allowances" />
<notebook>
<page string="Allowances">
<field name='allowance_ids' nolabel='1'>
<tree string='List' editable='bottom'>
<field name='fixed_allowance_ids' nolabel='1'>
<tree string="fixed_allowance">
<field name='allowance_id' />
<field name='allowance_name' />
<field name='amount' />
</tree>
</field>
</tree>
</field>
</page>
<page string="Deductions">
<field name='deduction_ids' nolabel='1'>
</field>
</page>
</notebook>
</sheet>
</form>
仍然没有显示任何记录。请帮我排序
已编辑
需要像这样返回 mu 结果吗?
dict: {'fixed_allowance_ids': [{'allowance_ids': [{'allowance_id': 1, 'allowance_name': 1}]}]}
已编辑
使用以下代码完成
模型类
def on_change_worker(self, cr, uid, ids, worker_id): 固定_v = {} 固定列表 v = {} 固定列表 = [] fixed_list_data = []
if worker_id:
ind_allowance_id = self.pool.get('bpl.allowance.individual.data').search(cr, uid, [('worker_id', '=', worker_id)])
ind_allowance_obj = self.pool.get('bpl.allowance.individual.data').browse(cr, uid, ind_allowance_id)[0]
for allowance_record in ind_allowance_obj.fixed_allowance_ids:
fixed_list.append({'allowance_id':allowance_record.allowance_id.id, 'allowance_name': allowance_record.allowance_name.id })
fixed_v['fixed_allowance_ids'] = fixed_list
fixed_list_data.append(fixed_v)
fixed_list_v['allowance_ids'] = fixed_list_data
return {'value':fixed_list_v}
view.xml
<page string="Allowances">
<field name='allowance_ids' nolabel='1'>
<field name='fixed_allowance_ids' nolabel='1'>
<tree string="fixed_allowance">
<field name='allowance_id' />
<field name='allowance_name' />
<field name='amount' />
</tree>
</field>
</field>
</page>
现在结果是这样的,但仍然需要在树视图上获取值
如果有任何关于获取准确值的建议,请在此处发布
【问题讨论】: