From 19dd109f75cbdc983f7a2be4bb2035c5932e4027 Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 4 Apr 2011 16:18:31 +0530 Subject: [PATCH] [IMP] hr_payroll:improved code to display salary rules as per the sequence of salary head bzr revid: mtr@mtr-20110404104831-zb30sau1ikzuufjl --- addons/hr_payroll/hr_payroll.py | 25 +++++++++---------------- addons/hr_payroll/hr_payroll_view.xml | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 9375d4c2184..1266aa34ef6 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -501,22 +501,18 @@ class hr_payslip(osv.osv): lines.append(r) rules.append(rl) for fn in field_names: -# if fn == 'applied_salary_rule': -# for r in rules: -# if r.id not in rul: -# rul.append(r.id) -# res[record.id] = {fn: rul} - if fn == 'appears_on_payslip_rule': - for r in rules: - if r.appears_on_payslip: - if r.id not in rul: - rul.append(r.id) - res[record.id] = {fn: rul} - elif fn == 'details_by_salary_head': + if fn == 'details_by_salary_head': + final_rules = [] for r in rules: if r.id not in rul: rul.append(r.id) - res[record.id] = {fn: rul} + cr.execute('''SELECT sr.id + FROM hr_salary_rule as sr, hr_salary_head as sh + WHERE sr.category_id = sh.id AND sr.id in %s + ORDER BY sh.sequence''',(tuple(rul),)) + for x in cr.fetchall(): + final_rules.append(x[0]) + res[record.id] = {fn: final_rules} return res def _compute(self, cr, uid, id, value, employee, contract, context=None): @@ -575,8 +571,6 @@ 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(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Applied Salary Rules', multi='applied_salary_rule'), - 'appears_on_payslip_rule': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Appears on Payslip', multi='appears_on_payslip_rule'), 'details_by_salary_head': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Details by Salary Head', multi='details_by_salary_head'), } _defaults = { @@ -1533,7 +1527,6 @@ class hr_salary_rule(osv.osv): 'expression_result':fields.char('Expression based on',size=1024, required=False, readonly=False, help='result will be affected to a variable'), 'parent_rule_id':fields.many2one('hr.salary.rule', 'Parent Salary Rule', select=True), } - _defaults = { 'python_compute': '''# basic\n# employee: hr.employee object or None\n# contract: hr.contract object or None\n\nresult = basic * 0.10''', 'conditions': 'True', diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index 755334ede43..ae5305a1dfe 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -290,7 +290,7 @@ - +