From efbd32bb3b70e4b9da918866b28be53fba71d5ca Mon Sep 17 00:00:00 2001 From: mtr Date: Thu, 24 Mar 2011 17:32:13 +0530 Subject: [PATCH 1/2] [IMP] hr_payroll:improved code in 'onchange_employee_id' function for condition_based_on=range bzr revid: mtr@mtr-20110324120213-14fuj571041mfqcm --- addons/hr_payroll/hr_payroll.py | 68 ++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index e4f59e083f7..17f1fd1ecf2 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -463,7 +463,7 @@ class hr_payslip(osv.osv): if res: result[record.id] = [x[0] for x in res] return result - + def _compute(self, cr, uid, id, value, context=None): rule_obj = self.pool.get('hr.salary.rule') contrib = rule_obj.browse(cr, uid, id, context=context) @@ -977,11 +977,12 @@ class hr_payslip(osv.osv): val = rul.amount * amt amt = val value = line.amount * amt - if line.condition_range_min or line.condition_range_max: - if ((value < line.condition_range_min) or (value > line.condition_range_max)): - value = 0.0 - else: - value = value + if line.condition_select == 'range': + if line.condition_range_min or line.condition_range_max: + if ((value < line.condition_range_min) or (value > line.condition_range_max)): + value = 0.0 + else: + value = value else: value = value except Exception, e: @@ -992,11 +993,12 @@ class hr_payslip(osv.osv): if line.parent_rule_id: for rul in [line.parent_rule_id]: value = value - 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 + if line.condition_select == 'range': + 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 @@ -1008,11 +1010,12 @@ class hr_payslip(osv.osv): if line.parent_rule_id: for rul in [line.parent_rule_id]: value = val - 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 = val + if line.condition_select == 'range': + 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 = val else: value = val @@ -1116,11 +1119,12 @@ class hr_payslip(osv.osv): val = rul.amount * amt amt = val value = salary_rule.amount * amt * days - if salary_rule.condition_range_min or salary_rule.condition_range_max: - if ((value < salary_rule.condition_range_min) or (value > salary_rule.condition_range_max)): - value = 0.0 - else: - value = value + if line.condition_select == 'range': + if salary_rule.condition_range_min or salary_rule.condition_range_max: + if ((value < salary_rule.condition_range_min) or (value > salary_rule.condition_range_max)): + value = 0.0 + else: + value = value else: value = value @@ -1132,11 +1136,12 @@ class hr_payslip(osv.osv): if salary_rule.parent_rule_id: for rul in [salary_rule.parent_rule_id]: value = salary_rule.amount * days - if salary_rule.condition_range_min or salary_rule.condition_range_max: - if ((salary_rule.amount < salary_rule.condition_range_min) or (salary_rule.amount > salary_rule.condition_range_max)): - value = 0.0 - else: - value = salary_rule.amount * days + if line.condition_select == 'range': + if salary_rule.condition_range_min or salary_rule.condition_range_max: + if ((salary_rule.amount < salary_rule.condition_range_min) or (salary_rule.amount > salary_rule.condition_range_max)): + value = 0.0 + else: + value = salary_rule.amount * days else: value = salary_rule.amount * days @@ -1148,11 +1153,12 @@ class hr_payslip(osv.osv): if salary_rule.parent_rule_id: for rul in [salary_rule.parent_rule_id]: value = val - if salary_rule.condition_range_min or salary_rule.condition_range_max: - if ((salary_rule.amount < salary_rule.condition_range_min) or (salary_rule.amount > salary_rule.condition_range_max)): - value = value - else: - value = val + if line.condition_select == 'range': + if salary_rule.condition_range_min or salary_rule.condition_range_max: + if ((salary_rule.amount < salary_rule.condition_range_min) or (salary_rule.amount > salary_rule.condition_range_max)): + value = value + else: + value = val else: value = val res['amount'] = salary_rule.amount From 5182562f9b960188e4711fef0343f1aff42ad739 Mon Sep 17 00:00:00 2001 From: mtr Date: Fri, 25 Mar 2011 18:45:12 +0530 Subject: [PATCH 2/2] [IMP] hr_payroll:added fields and code for tab i.e 'Applied Salary Rules' and 'Appears on Payslip' bzr revid: mtr@mtr-20110325131512-qzyzqemlqvc48yof --- addons/hr_payroll/hr_payroll.py | 74 +++++++++++++++++++++++---- addons/hr_payroll/hr_payroll_view.xml | 2 + 2 files changed, 65 insertions(+), 11 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 17f1fd1ecf2..9b390691c33 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -464,6 +464,66 @@ class hr_payslip(osv.osv): result[record.id] = [x[0] for x in res] return result + def _get_parent_structure(self, cr, uid, struct_id, context=None): + if not struct_id: + return [] + 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 _applied_salary_rule(self, cr, uid, ids, field_names, arg=None, context=None): + structure_obj = self.pool.get('hr.payroll.structure') + result = {} + for record in self.browse(cr, uid, ids, context=context): + function = record.struct_id.id + sal_structure = [] + lines = [] + rules = [] + rule = [] + if function: + sal_structure = self._get_parent_structure(cr, uid, [function], context=context) + for struct in sal_structure: + lines = structure_obj.browse(cr, uid, struct, context=context).rule_ids + for rl in lines: + if rl.child_ids: + for r in rl.child_ids: + lines.append(r) + rules.append(rl) + for r in rules: + if r.id not in rule: + rule.append(r.id) + result[record.id] = rule + return result + + def _appears_on_payslip_rule(self, cr, uid, ids, field_names, arg=None, context=None): + struct_obj = self.pool.get('hr.payroll.structure') + result = {} + for record in self.browse(cr, uid, ids, context=context): + structure = record.struct_id.id + sal_struct = [] + lines = [] + rules = [] + rule = [] + if structure: + sal_struct = self._get_parent_structure(cr, uid, [structure], context=context) + for struct in sal_struct: + lines = struct_obj.browse(cr, uid, struct, context=context).rule_ids + for rl in lines: + if rl.child_ids: + for r in rl.child_ids: + lines.append(r) + rules.append(rl) + for r in rules: + if r.appears_on_payslip: + if r.id not in rule: + rule.append(r.id) + result[record.id] = rule + return result + def _compute(self, cr, uid, id, value, context=None): rule_obj = self.pool.get('hr.salary.rule') contrib = rule_obj.browse(cr, uid, id, context=context) @@ -509,6 +569,9 @@ class hr_payslip(osv.osv): 'igross': fields.float('Calculaton Field', readonly=True, digits=(16, 2), help="Calculation field used for internal calculation, do not place this on form"), 'inet': fields.float('Calculaton Field', readonly=True, digits=(16, 2), help="Calculation field used for internal calculation, do not place this on form"), 'holiday_ids': fields.function(_get_holidays, method=True, type='one2many', relation='hr.holidays', string='Holiday Lines', required=False), + 'applied_salary_rule': fields.function(_applied_salary_rule, method=True, type='one2many', relation='hr.salary.rule', string='Applied Salary Rules', required=False), + 'appears_on_payslip_rule': fields.function(_appears_on_payslip_rule, method=True, type='one2many', relation='hr.salary.rule', string='Appears on Payslip', required=False), +# 'details_by_salary_head': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Details by Salary Head'), } _defaults = { 'date': lambda *a: time.strftime('%Y-%m-%d'), @@ -646,17 +709,6 @@ class hr_payslip(osv.osv): result = [x[0] for x in res] return result - def _get_parent_structure(self, cr, uid, struct_id, context=None): - if not struct_id: - return [] - 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 compute_sheet(self, cr, uid, ids, context=None): func_pool = self.pool.get('hr.payroll.structure') slip_line_pool = self.pool.get('hr.payslip.line') diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index 13fd6ed9260..3926c9bb19d 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -285,8 +285,10 @@ + +