From 8d903b60aa00db74156f0476cba58c854a7ce238 Mon Sep 17 00:00:00 2001 From: mtr Date: Fri, 13 May 2011 16:53:15 +0530 Subject: [PATCH] [IMP] hr_payroll: improved query for sum method of Payslips class bzr revid: mtr@mtr-20110513112315-qcaemrufa22gdnag --- addons/hr_payroll/hr_payroll.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 2889936cf17..4cf55582456 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -524,18 +524,13 @@ class hr_payslip(osv.osv): def sum(self, code, from_date, to_date=None): if to_date is None: to_date = datetime.now().strftime('%Y-%m-%d') - sum = 0.0 - self.cr.execute("SELECT pl.total, hp.credit_note\ + self.cr.execute("SELECT sum(case when hp.credit_note = False then (pl.total) else (-pl.total) end)\ FROM hr_payslip as hp, hr_payslip_line as pl \ WHERE hp.employee_id = %s AND hp.state in ('confirm','done') \ AND hp.date_from >= %s AND hp.date_to <= %s AND hp.id = pl.slip_id AND pl.code = %s", (self.employee_id, from_date, to_date, code)) - for r in cr.dictfetchall(): - if not r['credit_note']: - sum += r['total'] - else: - sum -= r['total'] - return sum + res = self.cr.fetchone() + return res and res[0] or 0.0 #we keep a dict with the result because a value can be overwritten by another rule with the same code result_dict = {}