From 0e076c40606dba1fa0adf4ec775fa59203c41a57 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Thu, 2 Jun 2011 18:30:43 +0530 Subject: [PATCH] [IMP] hr_payroll: Improve code of contribution report and update the help on register_id of rule object bzr revid: psi@tinyerp.co.in-20110602130043-lhfiercyh6bqp82p --- addons/hr_payroll/hr_payroll.py | 8 ++--- .../report/report_contribution_register.py | 34 ++++++++----------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index c6309188074..f8908d122c8 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -540,7 +540,7 @@ class hr_payslip(osv.osv): inputs = {} for input_line in payslip.input_line_ids: inputs[input_line.code] = input_line - + categories_obj = BrowsableObject(self.pool, cr, uid, payslip.employee_id.id, categories_dict) input_obj = InputLine(self.pool, cr, uid, payslip.employee_id.id, inputs) worked_days_obj = WorkedDays(self.pool, cr, uid, payslip.employee_id.id, worked_days) @@ -764,7 +764,7 @@ class hr_salary_rule(osv.osv): 'amount_python_compute':fields.text('Python Code'), 'amount_percentage_base':fields.char('Percentage based on',size=1024, required=False, readonly=False, help='result will be affected to a variable'), 'child_ids':fields.one2many('hr.salary.rule', 'parent_rule_id', 'Child Salary Rule'), - 'register_id':fields.many2one('hr.contribution.register', 'Contribution Register', help="Contribution register based on company"), + 'register_id':fields.many2one('hr.contribution.register', 'Contribution Register', help="Contribution register for the rule"), 'input_ids': fields.one2many('hr.rule.input', 'input_id', 'Inputs'), 'note':fields.text('Description'), } @@ -776,7 +776,7 @@ class hr_salary_rule(osv.osv): # employee: hr.employee object # contract: hr.contract object # rules: object containing the rules code (previously computed) -# categories: object containing the computed salary rule categories (sum of amount of all rules belonging to that category). +# categories: object containing the computed salary rule categories (sum of amount of all rules belonging to that category). # worked_days: object containing the computed worked days. # inputs: object containing the computed inputs. @@ -791,7 +791,7 @@ result = contract.wage * 0.10''', # employee: hr.employee object # contract: hr.contract object # rules: object containing the rules code (previously computed) -# categories: object containing the computed salary rule categories (sum of amount of all rules belonging to that category). +# categories: object containing the computed salary rule categories (sum of amount of all rules belonging to that category). # worked_days: object containing the computed worked days # inputs: object containing the computed inputs diff --git a/addons/hr_payroll/report/report_contribution_register.py b/addons/hr_payroll/report/report_contribution_register.py index 585495e7d52..bd9e00d3832 100644 --- a/addons/hr_payroll/report/report_contribution_register.py +++ b/addons/hr_payroll/report/report_contribution_register.py @@ -4,7 +4,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved +# Copyright (C) 2004-2010 Tiny SPRL (). All Rights Reserved # d$ # # This program is free software: you can redistribute it and/or modify @@ -47,30 +47,26 @@ class contribution_register_report(report_sxw.rml_parse): def _get_payslip_lines(self, obj): payslip_obj = self.pool.get('hr.payslip') payslip_line = self.pool.get('hr.payslip.line') + payslip_lines = [] res = [] - result = {} self.regi_total = 0.0 - self.cr.execute("SELECT pl.id, pl.slip_id from hr_payslip_line as pl "\ + self.cr.execute("SELECT pl.id from hr_payslip_line as pl "\ "LEFT JOIN hr_payslip AS hp on (pl.slip_id = hp.id) "\ "WHERE (hp.date_from >= %s) AND (hp.date_to <= %s) "\ "AND pl.register_id = %s "\ - "GROUP BY pl.slip_id, pl.sequence, pl.id, pl.category_id "\ - "ORDER BY pl.sequence", + "ORDER BY pl.slip_id, pl.sequence", (self.date_from, self.date_to, obj.id)) - for x in self.cr.fetchall(): - result.setdefault(x[1], []) - result[x[1]].append(x[0]) - for key, value in result.iteritems(): - for line in payslip_line.browse(self.cr, self.uid, value): - res.append({ - 'payslip_name': payslip_obj.browse(self.cr, self.uid, [key])[0].name, - 'name': line.name, - 'code': line.code, - 'quantity': line.quantity, - 'amount': line.amount, - 'total': line.total, - }) - self.regi_total += line.total + payslip_lines = [x[0] for x in self.cr.fetchall()] + for line in payslip_line.browse(self.cr, self.uid, payslip_lines): + res.append({ + 'payslip_name': line.slip_id.name, + 'name': line.name, + 'code': line.code, + 'quantity': line.quantity, + 'amount': line.amount, + 'total': line.total, + }) + self.regi_total += line.total return res report_sxw.report_sxw('report.contribution.register.lines', 'hr.contribution.register', 'hr_payroll/report/report_contribution_register.rml', parser=contribution_register_report)