Merge lp:~agilebg/hr-timesheet/fix-hr_attendance_analysis-report-timezone into lp:~hr-core-editors/hr-timesheet/7.0

Proposed by Lorenzo Battistini
Status: Work in progress
Proposed branch: lp:~agilebg/hr-timesheet/fix-hr_attendance_analysis-report-timezone
Merge into: lp:~hr-core-editors/hr-timesheet/7.0
Diff against target: 71 lines (+28/-9)
1 file modified
hr_attendance_analysis/wizard/print_calendar_report.py (+28/-9)
To merge this branch: bzr merge lp:~agilebg/hr-timesheet/fix-hr_attendance_analysis-report-timezone
Reviewer Review Type Date Requested Status
Alex Comba - Agile BG (community) Disapprove
Pedro Manuel Baeza Needs Resubmitting
Review via email: mp+221374@code.launchpad.net

Description of the change

[FIX] hr_attendance_analysis
using correct timezone to print the sign in/out time

To post a comment you must log in.
69. By Lorenzo Battistini

[FIX] hour and minutes

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Lorenzo,

I think your fix has a problem with times that after been converted to correct timezone change its date. For example: 29/05/2014 00:12 GMT+2 >> 28/05/2014 22:12 UTC.

Regards.

review: Needs Information (code review)
70. By Lorenzo Battistini

[FIX] problem with times that after been converted to correct timezone change its date.
For example: 29/05/2014 00:12 GMT+2 >> 28/05/2014 22:12 UTC

Revision history for this message
Lorenzo Battistini (elbati) wrote :

Pedro, right, thanks.

I added the conversion to UTC while searching for attendances within the current_date.
This way, if selected current_date is 29/05/2014 (for a user in GMT+2), the sign in at 28/05/2014 22:12 UTC will be included in current_date.
So, every datetime is always expressed in the timezone of the user.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

This project is now hosted on https://github.com/OCA/hr-timesheet. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

review: Needs Resubmitting
Revision history for this message
Alex Comba - Agile BG (tafaru) wrote :

Moved to https://github.com/OCA/hr-timesheet/pull/7
I prefer do not delete the proposal to keep all the associated comments that have been made.

review: Disapprove

Unmerged revisions

70. By Lorenzo Battistini

[FIX] problem with times that after been converted to correct timezone change its date.
For example: 29/05/2014 00:12 GMT+2 >> 28/05/2014 22:12 UTC

69. By Lorenzo Battistini

[FIX] hour and minutes

68. By Lorenzo Battistini

[FIX] hr_attendance_analysis
using correct timezone to print the sign in/out time

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hr_attendance_analysis/wizard/print_calendar_report.py'
--- hr_attendance_analysis/wizard/print_calendar_report.py 2013-11-19 13:32:00 +0000
+++ hr_attendance_analysis/wizard/print_calendar_report.py 2014-05-30 08:09:58 +0000
@@ -25,6 +25,7 @@
25from datetime import *25from datetime import *
26import math26import math
27import calendar27import calendar
28import pytz
2829
29class wizard_calendar_report(orm.TransientModel):30class wizard_calendar_report(orm.TransientModel):
30 31
@@ -86,6 +87,8 @@
86 employee_ids=form['employee_ids']87 employee_ids=form['employee_ids']
87 delta = to_date - from_date88 delta = to_date - from_date
88 max_number_of_attendances_per_day = 089 max_number_of_attendances_per_day = 0
90 active_tz = pytz.timezone(
91 context.get("tz","UTC") if context else "UTC")
8992
90 for employee_id in employee_ids:93 for employee_id in employee_ids:
91 employee_id = str(employee_id)94 employee_id = str(employee_id)
@@ -110,10 +113,16 @@
110 'signout_4': '',113 'signout_4': '',
111 }114 }
112 current_date_beginning = datetime.combine(current_date, time())115 current_date_beginning = datetime.combine(current_date, time())
113 str_current_date_beginning = current_date_beginning.strftime(116 current_date_beginning_utc = current_date_beginning.replace(
114 '%Y-%m-%d %H:%M:%S')117 tzinfo=active_tz).astimezone(pytz.utc)
115 current_date_end = datetime.combine(current_date, time())+ timedelta(1)118 str_current_date_beginning = (
116 str_current_date_end = current_date_end.strftime('%Y-%m-%d %H:%M:%S')119 current_date_beginning_utc.strftime('%Y-%m-%d %H:%M:%S'))
120 current_date_end = datetime.combine(
121 current_date, time()) + timedelta(1)
122 current_date_end_utc = current_date_end.replace(
123 tzinfo=active_tz).astimezone(pytz.utc)
124 str_current_date_end = (
125 current_date_end_utc.strftime('%Y-%m-%d %H:%M:%S'))
117 126
118 attendance_ids = attendance_pool.search(cr, uid, [127 attendance_ids = attendance_pool.search(cr, uid, [
119 ('employee_id','=',int(employee_id)),128 ('employee_id','=',int(employee_id)),
@@ -136,14 +145,24 @@
136 count = 1145 count = 1
137 for attendance in sorted(attendance_pool.browse(cr, uid, attendance_ids, context=context),146 for attendance in sorted(attendance_pool.browse(cr, uid, attendance_ids, context=context),
138 key=lambda x: x['name']):147 key=lambda x: x['name']):
139 days_by_employee[employee_id][str_current_date][148
140 'signin_'+str(count)] = attendance.name[11:16]149 attendance_start = datetime.strptime(
141 days_by_employee[employee_id][str_current_date][150 attendance.name, '%Y-%m-%d %H:%M:%S'
142 'signout_'+str(count)] = attendance.end_datetime[11:16]151 ).replace(tzinfo=pytz.utc).astimezone(active_tz)
152 attendance_end = datetime.strptime(
153 attendance.end_datetime, '%Y-%m-%d %H:%M:%S'
154 ).replace(tzinfo=pytz.utc).astimezone(active_tz)
155
156 days_by_employee[employee_id][str_current_date][
157 'signin_'+str(count)] = '%02d:%02d' % (
158 attendance_start.hour, attendance_start.minute)
159 days_by_employee[employee_id][str_current_date][
160 'signout_'+str(count)] = '%02d:%02d' % (
161 attendance_end.hour, attendance_end.minute)
143 count += 1162 count += 1
144 if len(attendance_ids) > max_number_of_attendances_per_day:163 if len(attendance_ids) > max_number_of_attendances_per_day:
145 max_number_of_attendances_per_day = len(attendance_ids)164 max_number_of_attendances_per_day = len(attendance_ids)
146 165
147 days_by_employee[employee_id][str_current_date][166 days_by_employee[employee_id][str_current_date][
148 'attendances'167 'attendances'
149 ] = current_total_attendances168 ] = current_total_attendances

Subscribers

People subscribed via source and target branches