From f0e3ce0dbbeb3ad8d5998501afbfb18a5d129712 Mon Sep 17 00:00:00 2001 From: mtr Date: Wed, 9 Mar 2011 17:00:03 +0530 Subject: [PATCH 1/4] [IMP] hr_payroll:improved code of _calculate(hr.payslip) for gross and net bzr revid: mtr@mtr-20110309113003-03rr094fnxwn5n35 --- addons/hr_payroll/hr_payroll.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 73c2a7e7b5e..ea39048d34c 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -377,6 +377,8 @@ class hr_payslip(osv.osv): allow = 0.0 deduct = 0.0 others = 0.0 + tot_amount = 0.0 + contract = rs.employee_id.contract_id obj = {'basic': contract.wage} if not contract.struct_id: @@ -406,10 +408,13 @@ class hr_payslip(osv.osv): allow += amount others -= contrib amount += contrib + tot_amount += amount salary_rule_pool.write(cr, uid, [line.id], {'total': amount}, context=context) record = { 'allounce': allow, 'deduction': deduct, + 'gross_amount': rs.basic_amount + allow, + 'net_amount': rs.basic_amount + tot_amount, 'other_pay': others, 'state': 'draft', 'total_pay': abs(contract.wage + allow + deduct) From 3fbb7333aba4af762681723cec7c43726ddda64b Mon Sep 17 00:00:00 2001 From: mtr Date: Thu, 10 Mar 2011 12:23:26 +0530 Subject: [PATCH 2/4] [IMP] hr_payroll:added code in onchange_employee_id for min and max range condition bzr revid: mtr@mtr-20110310065326-2vtu0z1fyy1esj09 --- addons/hr_payroll/hr_payroll.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 34b2dd4ad81..ad9761b7b85 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -956,11 +956,24 @@ class hr_payslip(osv.osv): raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e)) if line.amount_type == 'per': try: - value = line.amount * amt + if line.condition_range_min or line.condition_range_max: + if ((line.amount < line.condition_range_min) or (line.amount > line.condition_range_max)): + value = value + else: + value = line.amount * amt + else: + value = line.amount * amt except Exception, e: raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e)) + elif line.amount_type == 'fix': - value = line.amount + if line.condition_range_min or line.condition_range_max: + if ((line.amount < line.condition_range_min) or (line.amount > line.condition_range_max)): + value = value + else: + value = line.amount + else: + value = line.amount # elif line.amount_type == 'code': # Need some clarification so this option remains # value = slip_line_pool.execute_function(cr, uid, line.id, amt, context) # line.amount = value @@ -980,7 +993,11 @@ class hr_payslip(osv.osv): 'base': line.computational_expression } if line.appears_on_payslip: - update['value']['line_ids'].append(vals) + if line.condition_range_min or line.condition_range_max: + if not((line.amount < line.condition_range_min) or (line.amount > line.condition_range_max)): + update['value']['line_ids'].append(vals) + else: + update['value']['line_ids'].append(vals) basic = contract.wage number = sequence_obj.get(cr, uid, 'salary.slip') update['value'].update({ From 473a1541e1737f29c5ff9c91cbfc1337bda2550d Mon Sep 17 00:00:00 2001 From: mtr Date: Fri, 11 Mar 2011 14:27:40 +0530 Subject: [PATCH 3/4] [IMP] hr_payroll:added code in onchange_employee_id if salary structure has parent_id bzr revid: mtr@mtr-20110311085740-gkz19qlnpt38gowc --- addons/hr_payroll/hr_payroll.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index ad9761b7b85..fd85d272b78 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -917,19 +917,40 @@ class hr_payslip(osv.osv): return update contract = employee_id.contract_id + sal_structure = [] function = contract.struct_id.id + sal_structure.append(function) + if contract.struct_id.parent_id: + sal_structure.append(contract.struct_id.parent_id.id) + for s in sal_structure: + sal_struct = func_pool.read(cr, uid, s, ['parent_id'], context=context) + if sal_struct['parent_id']: + structure_id = sal_struct['parent_id'][0] + while(sal_struct['parent_id']): + if structure_id: + sal_struct = func_pool.browse(cr, uid, structure_id, context=context) + for struct_line in [sal_struct]: + structure_id = struct_line.parent_id + if structure_id: + sal_structure.append(structure_id.id) + lines = [] + rules = [] if function: - func = func_pool.read(cr, uid, function, ['rule_ids'], context=context) - lines = salary_rule_pool.browse(cr, uid, func['rule_ids'], context=context) + for struct in sal_structure: + func = func_pool.read(cr, uid, struct, ['rule_ids'], context=context) + lines = salary_rule_pool.browse(cr, uid, func['rule_ids'], context=context) + for rul in lines: + rules.append(rul) + ad = [] total = 0.0 obj = {'basic':contract.wage} - for line in lines: + for line in rules: cd = line.code.lower() obj[cd] = line.amount or 0.0 - for line in lines: + for line in rules: if line.category_id.code in ad: continue ad.append(line.category_id.code) @@ -1011,7 +1032,7 @@ class hr_payslip(osv.osv): 'contract_id': contract.id, 'company_id': employee_id.company_id.id }) - + for line in employee_id.line_ids: vals = { 'category_id': line.category_id.id, From 36366390b52ac97c45db40fdb7c9eaef4de1b2cd Mon Sep 17 00:00:00 2001 From: mtr Date: Fri, 11 Mar 2011 17:11:55 +0530 Subject: [PATCH 4/4] [IMP] hr_payroll:created a function to get parent_id of salary structure bzr revid: mtr@mtr-20110311114155-stpuykd37s02iyq1 --- addons/hr_payroll/hr_payroll.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index c846d8f5cf8..f59c47467fb 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -869,6 +869,15 @@ class hr_payslip(osv.osv): # self.write(cr, uid, [slip.id], update, context=context) # return True + def _get_parent_structure(self, cr, uid, struct_id, context=None): + parent = [] + for line in self.pool.get('hr.payroll.structure').browse(cr, uid, struct_id): + if line.parent_id: + parent.append(line.parent_id.id) + if parent: + parent = self._get_parent_structure(cr, uid, parent, context) + return struct_id + parent + def onchange_employee_id(self, cr, uid, ids, ddate, employee_id, context=None): func_pool = self.pool.get('hr.payroll.structure') slip_line_pool = self.pool.get('hr.payslip.line') @@ -923,21 +932,8 @@ class hr_payslip(osv.osv): sal_structure = [] function = contract.struct_id.id - - sal_structure.append(function) - if contract.struct_id.parent_id: - sal_structure.append(contract.struct_id.parent_id.id) - for s in sal_structure: - sal_struct = func_pool.read(cr, uid, s, ['parent_id'], context=context) - if sal_struct['parent_id']: - structure_id = sal_struct['parent_id'][0] - while(sal_struct['parent_id']): - if structure_id: - sal_struct = func_pool.browse(cr, uid, structure_id, context=context) - for struct_line in [sal_struct]: - structure_id = struct_line.parent_id - if structure_id: - sal_structure.append(structure_id.id) + if function: + sal_structure = self._get_parent_structure(cr, uid, [function], context=context) lines = [] rules = [] @@ -945,9 +941,9 @@ class hr_payslip(osv.osv): for struct in sal_structure: func = func_pool.read(cr, uid, struct, ['rule_ids'], context=context) lines = salary_rule_pool.browse(cr, uid, func['rule_ids'], context=context) - for rul in lines: - rules.append(rul) - + for rl in lines: + rules.append(rl) + ad = [] total = 0.0 obj = {'basic':contract.wage} @@ -955,7 +951,6 @@ class hr_payslip(osv.osv): cd = line.code.lower() obj[cd] = line.amount or 0.0 - for line in rules: if line.category_id.code in ad: continue