From dad7036ce2893f4c573f6b29890810f90fc651c5 Mon Sep 17 00:00:00 2001 From: "Denis Vermylen (dve)" Date: Fri, 21 Oct 2016 14:27:35 +0200 Subject: [PATCH] [FIX] hr_timesheet_attendance: correct attendance computation on timesheets Attendances (model hr.attendance) that overlapped different dates where not computed correctly in timesheets (model hr_timesheet_sheet.sheet.day). The difference in dates was not taken into account. This commit fixes this issue; attendances are now linked with the check_in date to hr_timesheet_sheet.sheet.day. (so 8 hours recorded from 20:00 to 04:00 the next day will be recorded as 8 hours on the first day) --- .../models/hr_timesheet_sheet.py | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/addons/hr_timesheet_attendance/models/hr_timesheet_sheet.py b/addons/hr_timesheet_attendance/models/hr_timesheet_sheet.py index acdd32820f4..965789a35ed 100644 --- a/addons/hr_timesheet_attendance/models/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_attendance/models/hr_timesheet_sheet.py @@ -122,15 +122,7 @@ class hr_timesheet_sheet_sheet_day(models.Model): sheet_id, timezone, SUM(total_timesheet) as total_timesheet, - 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' 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) - END /60 as total_attendance + SUM(total_attendance) /60 as total_attendance FROM (( select @@ -139,7 +131,6 @@ class hr_timesheet_sheet_sheet_day(models.Model): 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 account_analytic_line l @@ -156,9 +147,12 @@ class hr_timesheet_sheet_sheet_day(models.Model): (a.check_in AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC'))::date as name, s.id as sheet_id, 0.0 as total_timesheet, - 0 as orphan_attendances, - SUM((EXTRACT(hour FROM (a.check_out AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC'))) * 60 + EXTRACT(minute FROM (a.check_out AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC')))) - - (EXTRACT(hour FROM (a.check_in AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC'))) * 60 + EXTRACT(minute FROM (a.check_in AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC'))))) as total_attendance + SUM(DATE_PART('day', (a.check_out AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC')) + - (a.check_in AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC')) ) * 60 * 24 + + DATE_PART('hour', (a.check_out AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC')) + - (a.check_in AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC')) ) * 60 + + DATE_PART('minute', (a.check_out AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC')) + - (a.check_in AT TIME ZONE 'UTC' AT TIME ZONE coalesce(p.tz, 'UTC')) )) as total_attendance from hr_attendance a LEFT JOIN hr_timesheet_sheet_sheet s