Purnendu Singh (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-hr_onchange_employee_imp-psi into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-hr_onchange_employee_imp-psi/+merge/124387

Hello,

Improve the onchange_employee method on payslip object so it will not give any 
trackback in following scenario:

When there is a contract for selected employee but salary structure is not 
define on that contract.

thanks,
purnendu singh

-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-hr_onchange_employee_imp-psi/+merge/124387
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-hr_onchange_employee_imp-psi.
=== modified file 'hr_payroll/hr_payroll.py'
--- hr_payroll/hr_payroll.py	2012-08-13 05:05:23 +0000
+++ hr_payroll/hr_payroll.py	2012-09-14 11:23:23 +0000
@@ -666,29 +666,30 @@
                     '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)

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to