0

我需要加载工人的津贴和扣除额。
津贴 2 种固定和可变。
扣除额也有 3 种固定、可变和特殊。

然后我的班级有这样的关系
津贴 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}

视图.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): 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['fixed_allowance_ids'] = fixed_list
    fixed_list_data.append(fixed_v)
    fixed_list_v['allowance_ids'] = fixed_list_data
    return {'value':fixed_list_v}

视图.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>

现在结果是这样的,但仍然需要在树视图上获取值

如果有任何建议以获取准确值,请在此处发布

屏幕

4

1 回答 1

1

您需要像这样返回:

dict: {'fixed_allowance_ids': [{'allowance_id': 1, 'allowance_name': 1}, {'allowance_id': 2, 'allowance_name': 2}]}

它应该适合你。

于 2013-04-30T11:50:20.797 回答