From 89b312484b12c368ce1d36532f97989773d6b2f2 Mon Sep 17 00:00:00 2001 From: ced <> Date: Wed, 4 Jul 2007 08:38:20 +0000 Subject: [PATCH] hr_timesheet_sheet: fix difference in view by day bzr revid: ced-3efbc707ade4d84a9b9091e13d94f901fc6db0b4 --- .../hr_timesheet_sheet/hr_timesheet_sheet.py | 77 +++++++++++-------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index 8e0ad6e69ae..fa48422fa6c 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -377,44 +377,53 @@ class hr_timesheet_sheet_sheet_day(osv.osv): def init(self, cr): cr.execute("""create or replace view hr_timesheet_sheet_sheet_day as SELECT - MAX(id) as id, + id, name, sheet_id, - SUM(total_timesheet) as total_timesheet, - CASE WHEN SUM(total_attendance) < 0 - THEN (SUM(total_attendance) + - CASE WHEN current_date <> name - THEN 1440 - ELSE (EXTRACT(hour FROM current_time) * 60) + EXTRACT(minute FROM current_time) - END - ) - ELSE SUM(total_attendance) - END /60 as total_attendance, - (SUM(total_attendance) - SUM(total_timesheet)) as total_difference + total_timesheet, + total_attendance, + (total_attendance - total_timesheet) AS total_difference FROM (( - select - min(hrt.id) as id, - l.date::date as name, - hrt.sheet_id as sheet_id, - sum(l.unit_amount) as total_timesheet, - 0.0 as total_attendance - from - hr_analytic_timesheet hrt - left join account_analytic_line l on (l.id = hrt.line_id) - group by l.date::date, hrt.sheet_id - ) union ( - select - -min(a.id) as id, - a.name::date as name, - a.sheet_id as sheet_id, - 0.0 as total_timesheet, - SUM(((EXTRACT(hour FROM a.name) * 60) + EXTRACT(minute FROM a.name)) * (CASE WHEN a.action = 'sign_in' THEN -1 ELSE 1 END)) as total_attendance - from - hr_attendance a - group by a.name::date, a.sheet_id - )) AS foo - GROUP BY name, sheet_id""") + SELECT + MAX(id) as id, + name, + sheet_id, + SUM(total_timesheet) as total_timesheet, + CASE WHEN SUM(total_attendance) < 0 + THEN (SUM(total_attendance) + + CASE WHEN current_date <> name + THEN 1440 + ELSE (EXTRACT(hour FROM current_time) * 60) + EXTRACT(minute FROM current_time) + END + ) + ELSE SUM(total_attendance) + END /60 as total_attendance + FROM + (( + select + min(hrt.id) as id, + l.date::date as name, + hrt.sheet_id as sheet_id, + sum(l.unit_amount) as total_timesheet, + 0.0 as total_attendance + from + hr_analytic_timesheet hrt + left join account_analytic_line l on (l.id = hrt.line_id) + group by l.date::date, hrt.sheet_id + ) union ( + select + -min(a.id) as id, + a.name::date as name, + a.sheet_id as sheet_id, + 0.0 as total_timesheet, + SUM(((EXTRACT(hour FROM a.name) * 60) + EXTRACT(minute FROM a.name)) * (CASE WHEN a.action = 'sign_in' THEN -1 ELSE 1 END)) as total_attendance + from + hr_attendance a + group by a.name::date, a.sheet_id + )) AS foo + GROUP BY name, sheet_id + )) AS bar""") hr_timesheet_sheet_sheet_day()