[IMP] hr_payroll: improve the onchange employee method on payslip so it will not give traceback in case contract is available for the selected employee and salary structure is not there

bzr revid: psi@tinyerp.com-20120914111847-irocinmn1f29wc5d
This commit is contained in:
Purnendu Singh (OpenERP) 2012-09-14 16:48:47 +05:30
parent 35b884551a
commit 428259a2b6
1 changed files with 13 additions and 12 deletions

View File

@ -666,29 +666,30 @@ class hr_payslip(osv.osv):
'company_id': employee_id.company_id.id
})
struct_record = False
if not context.get('contract', False):
#fill with the first contract of the employee
contract_ids = self.get_contract(cr, uid, employee_id, date_from, date_to, context=context)
res['value'].update({
'struct_id': contract_ids and contract_obj.read(cr, uid, contract_ids[0], ['struct_id'], context=context)['struct_id'][0] or False,
'contract_id': contract_ids and contract_ids[0] or False,
})
else:
if contract_id:
#set the list of contract for which the input have to be filled
contract_ids = [contract_id]
#fill the structure with the one on the selected contract
contract_record = contract_obj.browse(cr, uid, contract_id, context=context)
res['value'].update({
'struct_id': contract_record.struct_id.id,
'contract_id': contract_id
})
else:
#if we don't give the contract, then the input to fill should be for all current contracts of the employee
contract_ids = self.get_contract(cr, uid, employee_id, date_from, date_to, context=context)
if not contract_ids:
return res
if not contract_ids:
return res
contract_record = contract_obj.browse(cr, uid, contract_ids[0], context=context)
res['value'].update({
'contract_id': contract_record and contract_record.id or False
})
struct_record = contract_record and contract_record.struct_id or False
if not struct_record:
return res
res['value'].update({
'struct_id': struct_record.id,
})
#computation of the salary input
worked_days_line_ids = self.get_worked_day_lines(cr, uid, contract_ids, date_from, date_to, context=context)
input_line_ids = self.get_inputs(cr, uid, contract_ids, date_from, date_to, context=context)