OpenERP one2many和one2many

时间:2013-04-30 10:04:10

标签: python xml openerp

我需要加载工人的津贴和扣除。
津贴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>

仍然没有显示任何记录。请帮助我对此进行排序

EDITED

需要像这样返回mu结果。?

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

EDITED

完成以下代码

模型类

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}

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>

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

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

screen

1 个答案:

答案 0 :(得分:1)

你需要像这样回来:

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

它应该适合你。