[FIX] hr_timesheet: worked hours summary when sign in without sign out

In a timesheet, when a sign in is added, and a sign out
is not following, the current time is took as sign out value.

Rev. dbb2a669f4 corrected an issue
regarding the worked hours summary not taking into account
the employee timezone.
This timezone has to be applied on the current_time also.

e.g: For an employee being in timezone UTC + 1
If the current_time is presently 12:00 (UTC+1)
If the employee set his sign in to 10:00
and do not entered a sign out
The hours summary table displayed 1:00 of worked hours,
based on computation (11:00 - 10:00)
11:00 being 12:00 but in timezone UTC

Besides, another issue was present when entering
a sign in at midnight exactly without a sign out:
If the employee set his sign in to 00:00:00
and do not set a sign out, worked hours displayed 0 worked hours
whatever the current time.

Fixes #5379
Closes #5378
Closes #5503
This commit is contained in:
Denis Ledoux 2015-02-27 11:55:45 +01:00
parent e2fa66b05d
commit 3bf1615ad4
1 changed files with 10 additions and 5 deletions

View File

@ -534,12 +534,13 @@ class hr_timesheet_sheet_sheet_day(osv.osv):
MAX(id) as id,
name,
sheet_id,
timezone,
SUM(total_timesheet) as total_timesheet,
CASE WHEN SUM(total_attendance) < 0
CASE WHEN SUM(orphan_attendances) != 0
THEN (SUM(total_attendance) +
CASE WHEN current_date <> name
THEN 1440
ELSE (EXTRACT(hour FROM current_time AT TIME ZONE 'UTC') * 60) + EXTRACT(minute FROM current_time AT TIME ZONE 'UTC')
ELSE (EXTRACT(hour FROM current_time AT TIME ZONE 'UTC' AT TIME ZONE coalesce(timezone, 'UTC')) * 60) + EXTRACT(minute FROM current_time AT TIME ZONE 'UTC' AT TIME ZONE coalesce(timezone, 'UTC'))
END
)
ELSE SUM(total_attendance)
@ -548,21 +549,25 @@ class hr_timesheet_sheet_sheet_day(osv.osv):
((
select
min(hrt.id) as id,
'UTC' as timezone,
l.date::date as name,
s.id as sheet_id,
sum(l.unit_amount) as total_timesheet,
0 as orphan_attendances,
0.0 as total_attendance
from
hr_analytic_timesheet hrt
JOIN account_analytic_line l ON l.id = hrt.line_id
LEFT JOIN hr_timesheet_sheet_sheet s ON s.id = hrt.sheet_id
group by l.date::date, s.id
group by l.date::date, s.id, timezone
) union (
select
-min(a.id) as id,
p.tz as timezone,
(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(CASE WHEN a.action = 'sign_in' THEN -1 ELSE 1 END) as orphan_attendances,
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
@ -577,9 +582,9 @@ class hr_timesheet_sheet_sheet_day(osv.osv):
LEFT JOIN res_partner p
ON u.partner_id = p.id
WHERE action in ('sign_in', 'sign_out')
group by (a.name AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC'))::date, s.id
group by (a.name AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC'))::date, s.id, timezone
)) AS foo
GROUP BY name, sheet_id
GROUP BY name, sheet_id, timezone
)) AS bar""")
hr_timesheet_sheet_sheet_day()