0

I need to load workers's allowances & deductions.
allowances 2 types fixed & variable.
deductions also 3 types fixed , variable & special.

then my classes have relationship like this
allowance one2many fixed
allowance one2many variable

deduction one2many fixed
deduction one2many variable
deduction one2many special

my last requirment is to load those deductions and allowances in two '' tags then i wrote a method for onchange_worker.but its not worked & hope you will help me to sortout this issue
thanks
(initially i wrote code for fixed allowances)

function in my class

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>

still not shows any records.please help me to sort this

EDITED

need to return mu result like this.?

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

EDITED

done with below codes

model class

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>

now result comes like this but still need to get values on tree view

if any suggestion to get exact values, please post here

screen

1 Answer 1

1

You need to return like this:

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

It should work for you.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.