[FIX] hr_timesheet_sheet: display timesheet by day summary in employee tz

If an employee in UTC + 1 (Europe/Brussels) entered an attendance from January 2 00:00 to Januay 2 23:59, the summary by day table displayed two different lines, for two different days:
 - 1 hour on January 1 from 23:00 to 23:59
 - 22:59 hours on January 2 from 00:00 to 22:59

 Which is obviously wrong, the employee, in its own time zone, worked on January 2 only.
This commit is contained in:
Denis Ledoux 2015-01-07 12:22:29 +01:00
parent 91911159f5
commit dbb2a669f4
1 changed files with 11 additions and 3 deletions

View File

@ -559,16 +559,24 @@ class hr_timesheet_sheet_sheet_day(osv.osv):
) union (
select
-min(a.id) as id,
a.name::date as name,
(a.name AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC'))::date as name,
s.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
SUM(((EXTRACT(hour FROM (a.name AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC'))) * 60) + EXTRACT(minute FROM (a.name AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC')))) * (CASE WHEN a.action = 'sign_in' THEN -1 ELSE 1 END)) as total_attendance
from
hr_attendance a
LEFT JOIN hr_timesheet_sheet_sheet s
ON s.id = a.sheet_id
JOIN hr_employee e
ON a.employee_id = e.id
JOIN resource_resource r
ON e.resource_id = r.id
LEFT JOIN res_users u
ON r.user_id = u.id
LEFT JOIN res_partner p
ON u.partner_id = p.id
WHERE action in ('sign_in', 'sign_out')
group by a.name::date, s.id
group by (a.name AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC'))::date, s.id
)) AS foo
GROUP BY name, sheet_id
)) AS bar""")