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
1=== modified file 'hr_attendance_analysis/wizard/print_calendar_report.py'
2--- hr_attendance_analysis/wizard/print_calendar_report.py 2013-11-19 13:32:00 +0000
3+++ hr_attendance_analysis/wizard/print_calendar_report.py 2014-05-30 08:09:58 +0000
4@@ -25,6 +25,7 @@
5 from datetime import *
6 import math
7 import calendar
8+import pytz
9
10 class wizard_calendar_report(orm.TransientModel):
11
12@@ -86,6 +87,8 @@
13 employee_ids=form['employee_ids']
14 delta = to_date - from_date
15 max_number_of_attendances_per_day = 0
16+ active_tz = pytz.timezone(
17+ context.get("tz","UTC") if context else "UTC")
18
19 for employee_id in employee_ids:
20 employee_id = str(employee_id)
21@@ -110,10 +113,16 @@
22 'signout_4': '',
23 }
24 current_date_beginning = datetime.combine(current_date, time())
25- str_current_date_beginning = current_date_beginning.strftime(
26- '%Y-%m-%d %H:%M:%S')
27- current_date_end = datetime.combine(current_date, time())+ timedelta(1)
28- str_current_date_end = current_date_end.strftime('%Y-%m-%d %H:%M:%S')
29+ current_date_beginning_utc = current_date_beginning.replace(
30+ tzinfo=active_tz).astimezone(pytz.utc)
31+ str_current_date_beginning = (
32+ current_date_beginning_utc.strftime('%Y-%m-%d %H:%M:%S'))
33+ current_date_end = datetime.combine(
34+ current_date, time()) + timedelta(1)
35+ current_date_end_utc = current_date_end.replace(
36+ tzinfo=active_tz).astimezone(pytz.utc)
37+ str_current_date_end = (
38+ current_date_end_utc.strftime('%Y-%m-%d %H:%M:%S'))
39
40 attendance_ids = attendance_pool.search(cr, uid, [
41 ('employee_id','=',int(employee_id)),
42@@ -136,14 +145,24 @@
43 count = 1
44 for attendance in sorted(attendance_pool.browse(cr, uid, attendance_ids, context=context),
45 key=lambda x: x['name']):
46- days_by_employee[employee_id][str_current_date][
47- 'signin_'+str(count)] = attendance.name[11:16]
48- days_by_employee[employee_id][str_current_date][
49- 'signout_'+str(count)] = attendance.end_datetime[11:16]
50+
51+ attendance_start = datetime.strptime(
52+ attendance.name, '%Y-%m-%d %H:%M:%S'
53+ ).replace(tzinfo=pytz.utc).astimezone(active_tz)
54+ attendance_end = datetime.strptime(
55+ attendance.end_datetime, '%Y-%m-%d %H:%M:%S'
56+ ).replace(tzinfo=pytz.utc).astimezone(active_tz)
57+
58+ days_by_employee[employee_id][str_current_date][
59+ 'signin_'+str(count)] = '%02d:%02d' % (
60+ attendance_start.hour, attendance_start.minute)
61+ days_by_employee[employee_id][str_current_date][
62+ 'signout_'+str(count)] = '%02d:%02d' % (
63+ attendance_end.hour, attendance_end.minute)
64 count += 1
65 if len(attendance_ids) > max_number_of_attendances_per_day:
66 max_number_of_attendances_per_day = len(attendance_ids)
67-
68+
69 days_by_employee[employee_id][str_current_date][
70 'attendances'
71 ] = current_total_attendances

Subscribers

People subscribed via source and target branches