From 51543fa458bfcdf8d702596aa44c90d78b0b8eb9 Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 25 Apr 2011 12:55:10 +0530 Subject: [PATCH 1/4] [IMP] hr_payroll:added field 'quantity' on salary rules,modified computation engine and demo data bzr revid: mtr@mtr-20110425072510-9f7tbuo9w3q3qq30 --- addons/hr_payroll/hr_payroll.py | 13 +++++++++++-- addons/hr_payroll/hr_payroll_demo.xml | 10 ++++++++-- addons/hr_payroll/hr_payroll_view.xml | 3 ++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 6757b57c417..b3434293342 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -500,6 +500,7 @@ class hr_payslip(osv.osv): for rule in self.pool.get('hr.salary.rule').browse(cr, uid, sorted_rule_ids, context=context): key = rule.code + '-' + str(contract.id) localdict['result'] = None + localdict.update({'quantity': rule.quantity or None}) #check if the rule can be applied if self.pool.get('hr.salary.rule').satisfy_condition(cr, uid, rule.id, localdict, context=context) and rule.id not in blacklist: #compute the amount of the rule @@ -532,10 +533,12 @@ class hr_payslip(osv.osv): 'register_id': rule.register_id.id, 'total': amount, 'employee_id': contract.employee_id.id, + 'quantity': rule.quantity, } else: #blacklist this rule and its children blacklist += [id for id, seq in self.pool.get('hr.salary.rule')._recursive_search_of_rules(cr, uid, [rule], context=context)] + result = [value for code, value in result_dict.items()] return result @@ -640,6 +643,7 @@ class hr_salary_rule(osv.osv): 'name':fields.char('Name', size=256, required=True, readonly=False), 'code':fields.char('Code', size=64, required=True), 'sequence': fields.integer('Sequence', required=True, help='Use to arrange calculation sequence'), + 'quantity': fields.char('Quantity', size=256), 'category_id':fields.many2one('hr.salary.head', 'Salary Head', required=True), 'active':fields.boolean('Active', help="If the active field is set to false, it will allow you to hide the salary rule without removing it."), 'appears_on_payslip': fields.boolean('Appears on Payslip', help="Used for the display of rule on payslip"), @@ -711,6 +715,7 @@ result = rules['NET'] > heads['NET'] * 0.10''', 'amount_select': 'fix', 'amount_fix': 0.0, 'amount_percentage': 0.0, + 'quantity': 1, } def _recursive_search_of_rules(self, cr, uid, rule_ids, context=None): @@ -733,10 +738,14 @@ result = rules['NET'] > heads['NET'] * 0.10''', """ rule = self.browse(cr, uid, rule_id, context=context) if rule.amount_select == 'fix': - return rule.amount_fix + try: + return rule.amount_fix * eval(rule.quantity, localdict) + except: + raise osv.except_osv(_('Error'), _('Wrong quantity defined for salary rule %s (%s)')% (rule.name, rule.code)) elif rule.amount_select == 'percentage': try: - return rule.amount_percentage * eval(rule.amount_percentage_base, localdict) / 100 + amount = rule.amount_percentage * eval(rule.amount_percentage_base, localdict) / 100 + return amount * eval(rule.quantity, localdict) except: raise osv.except_osv(_('Error'), _('Wrong percentage base defined for salary rule %s (%s)')% (rule.name, rule.code)) else: diff --git a/addons/hr_payroll/hr_payroll_demo.xml b/addons/hr_payroll/hr_payroll_demo.xml index 24736cbb9c2..c90cde78b94 100644 --- a/addons/hr_payroll/hr_payroll_demo.xml +++ b/addons/hr_payroll/hr_payroll_demo.xml @@ -12,6 +12,7 @@ House Rent Allowance + 1 @@ -21,6 +22,7 @@ Conveyance Allowance + 1 @@ -30,6 +32,7 @@ PT Professional Tax + 1 @@ -40,6 +43,7 @@ PF Provident Fund + 1 @@ -49,11 +53,13 @@ Conveyance Allowance For Paolino + 1 - code - result = worked_days['WORK100']['number_of_days'] * 1 + fix + + worked_days['WORK100']['number_of_days'] MA Meal Voucher diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index e1efc9d7f0c..8aae0d37046 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -546,7 +546,8 @@ - + + From 3c877bb4c78b01803c7a079b6bab81e8a6ae0bb8 Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 25 Apr 2011 15:25:37 +0530 Subject: [PATCH 2/4] [IMP] hr_payroll:removed qty from demo,improved search engine,made qty mandatory and added tooltip bzr revid: mtr@mtr-20110425095537-ewmhlikkh5i50jyg --- addons/hr_payroll/hr_payroll.py | 5 ++--- addons/hr_payroll/hr_payroll_demo.xml | 5 ----- addons/hr_payroll/hr_payroll_view.xml | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index b3434293342..57fbe2df201 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -500,7 +500,6 @@ class hr_payslip(osv.osv): for rule in self.pool.get('hr.salary.rule').browse(cr, uid, sorted_rule_ids, context=context): key = rule.code + '-' + str(contract.id) localdict['result'] = None - localdict.update({'quantity': rule.quantity or None}) #check if the rule can be applied if self.pool.get('hr.salary.rule').satisfy_condition(cr, uid, rule.id, localdict, context=context) and rule.id not in blacklist: #compute the amount of the rule @@ -643,7 +642,7 @@ class hr_salary_rule(osv.osv): 'name':fields.char('Name', size=256, required=True, readonly=False), 'code':fields.char('Code', size=64, required=True), 'sequence': fields.integer('Sequence', required=True, help='Use to arrange calculation sequence'), - 'quantity': fields.char('Quantity', size=256), + 'quantity': fields.char('Quantity', size=256, help="It is used in computation for percentage and fixed amount.For e.g. A rule for Meal Voucher having fixed amount of 1€ can have its quantity defined in expression like worked_days['WORK100']['number_of_days']."), 'category_id':fields.many2one('hr.salary.head', 'Salary Head', required=True), 'active':fields.boolean('Active', help="If the active field is set to false, it will allow you to hide the salary rule without removing it."), 'appears_on_payslip': fields.boolean('Appears on Payslip', help="Used for the display of rule on payslip"), @@ -715,7 +714,7 @@ result = rules['NET'] > heads['NET'] * 0.10''', 'amount_select': 'fix', 'amount_fix': 0.0, 'amount_percentage': 0.0, - 'quantity': 1, + 'quantity': '1', } def _recursive_search_of_rules(self, cr, uid, rule_ids, context=None): diff --git a/addons/hr_payroll/hr_payroll_demo.xml b/addons/hr_payroll/hr_payroll_demo.xml index c90cde78b94..db903fbabfe 100644 --- a/addons/hr_payroll/hr_payroll_demo.xml +++ b/addons/hr_payroll/hr_payroll_demo.xml @@ -12,7 +12,6 @@ House Rent Allowance - 1 @@ -22,7 +21,6 @@ Conveyance Allowance - 1 @@ -32,7 +30,6 @@ PT Professional Tax - 1 @@ -43,7 +40,6 @@ PF Provident Fund - 1 @@ -53,7 +49,6 @@ Conveyance Allowance For Paolino - 1 diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index 8aae0d37046..6c0f615e3e7 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -547,7 +547,7 @@ - + From 122d51a2d7b49a02804925b99704d9427e8f2f8a Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 25 Apr 2011 15:55:02 +0530 Subject: [PATCH 3/4] [IMP] hr_payroll:improved exception message string bzr revid: mtr@mtr-20110425102502-6basvgqilrh664th --- addons/hr_payroll/hr_payroll.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 57fbe2df201..ecfc417c90e 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -746,7 +746,7 @@ result = rules['NET'] > heads['NET'] * 0.10''', amount = rule.amount_percentage * eval(rule.amount_percentage_base, localdict) / 100 return amount * eval(rule.quantity, localdict) except: - raise osv.except_osv(_('Error'), _('Wrong percentage base defined for salary rule %s (%s)')% (rule.name, rule.code)) + raise osv.except_osv(_('Error'), _('Wrong percentage base/quantity defined for salary rule %s (%s)')% (rule.name, rule.code)) else: try: eval(rule.amount_python_compute, localdict, mode='exec', nocopy=True) From 30564f93e9fffe2dfaed90743229ed6ac142dbe7 Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 25 Apr 2011 17:34:30 +0530 Subject: [PATCH 4/4] [IMP] hr_payroll:again improved exception message string bzr revid: mtr@mtr-20110425120430-kacidzhufm6n25q7 --- addons/hr_payroll/hr_payroll.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index ecfc417c90e..27de59c8f71 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -746,7 +746,7 @@ result = rules['NET'] > heads['NET'] * 0.10''', amount = rule.amount_percentage * eval(rule.amount_percentage_base, localdict) / 100 return amount * eval(rule.quantity, localdict) except: - raise osv.except_osv(_('Error'), _('Wrong percentage base/quantity defined for salary rule %s (%s)')% (rule.name, rule.code)) + raise osv.except_osv(_('Error'), _('Wrong percentage base or quantity defined for salary rule %s (%s)')% (rule.name, rule.code)) else: try: eval(rule.amount_python_compute, localdict, mode='exec', nocopy=True)