The problem is not that attendances are timestamped in utc (all the times are timestamped in utc in OpenERP) but the fact that OpenERP developers have not realized on which things this kind of forcing openERP to use utc time in database affects. Because timezone problems are like ripples, first they look really small and irrelevant but they grow bigger and bigger...
Anyway, here is temporary solution for your problem however like I said timezone problems are like ripples and you may encounter them in future in many places where you are not expecting them so be prepared for that. And as I don't use timesheets myself I didn't test this totally I just checked that the problem you described doesn't appear anymore. I.e., I made this fix just out of curiosity not because it would help me so test it properly.
And remember, this trick is just what it is: a trick which makes it look like the problem is solved but it isn't fully solved. So this solution is like a painkiller it removes the pain but doesn't remove the reason for the pain.
Remove all you attendance data (old data is not updated so they will still appear on the wrong sheet even after this modification so you have to remove it).
Open file [path to your openerp addons]/hr_timesheet_sheet/hr_timesheet_sheet.py
It would be better to do your own module, that inherits from existing implementation, for this because as you update your OpenERP all these changes done directly to the source code will vanish.
In the beginning of file add:
import pytz
pytz is a python module for handling timezones. Then go to line 367 (this is in class hr_attendance in function _sheet)
there is for loop looking like this:
for attendance in self.browse(cursor, user, ids, context=context):
date_to = datetime.strftime(datetime.strptime(attendance.name[0:10], '%Y-%m-%d'), '%Y-%m-%d %H:%M:%S')
sheet_ids = sheet_obj.search(cursor, user,
[('date_to', '>=', date_to), ('date_from', '<=', attendance.name),
('employee_id', '=', attendance.employee_id.id)],
context=context)
if sheet_ids:
# [0] because only one sheet possible for an employee between 2 dates
res[attendance.id] = sheet_obj.name_get(cursor, user, sheet_ids, context=context)[0]
add these line to this loop
cursor.execute("select rp.tz as tz from res_partner as rp, res_users as ru where ru.id=%s and ru.partner_id=rp.id", (user,))
tz = cursor.dictfetchall()
tz = pytz.timezone(tz[0]['tz']) or pytz.utc
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
date_from = pytz.utc.localize(datetime.strptime(attendance.name, DATETIME_FORMAT)).astimezone(tz)
date_to = pytz.utc.localize(datetime.strptime(date_to, DATETIME_FORMAT)).astimezone(tz)
So the final version of this for loop looks like this
for attendance in self.browse(cursor, user, ids, context=context):
date_to = datetime.strftime(datetime.strptime(attendance.name[0:10], '%Y-%m-%d'), '%Y-%m-%d %H:%M:%S')
cursor.execute("select rp.tz as tz from res_partner as rp, res_users as ru where ru.id=%s and ru.partner_id=rp.id", (user,))
tz = cursor.dictfetchall()
tz = pytz.timezone(tz[0]['tz']) or pytz.utc
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
date_from = pytz.utc.localize(datetime.strptime(attendance.name, DATETIME_FORMAT)).astimezone(tz)
date_to = pytz.utc.localize(datetime.strptime(date_to, DATETIME_FORMAT)).astimezone(tz)
sheet_ids = sheet_obj.search(cursor, user,
[('date_to', '>=', date_to), ('date_from', '<=', date_from),
('employee_id', '=', attendance.employee_id.id)],
context=context)
if sheet_ids:
# [0] because only one sheet possible for an employee between 2 dates
res[attendance.id] = sheet_obj.name_get(cursor, user, sheet_ids, context=context)[0]
NOTE: in python indentation matters so copy pasting this to your code may cause indentation failures so be sure that indentation are right (I'm not sure how much you have experience about python so thought that this is good to mention).
3.Restart your openERP server with parameter -u hr_timesheet_sheet so that hr_timesheet_sheet module is updated.
Well, I tried messing around with the system timezone to try and compensate for this bug but it messed too many other things up, like email times and dates, file modification dates etc. It seems like this should be such an easy bug to fix, though I would have no idea how. Can't one of you coding gurus come to the rescue?:)
we are having a similar issue with Attendances being messed up (I think same UTC issue is the core of our problem as well) http://help.openerp.com/question/31908/how-to-get-attendance-be-assigned-to-the-correct-day-for-anyone-who-is-not-in-the-utc-timezone. In our case we want a report for Attendances (to show overtime worked in a monthly report to all employees). To overcome this issue (at least on the surface) we kind of fake the output time & date in the pdf report that is being generated. Not a real solution but a cosmetical solution that helps us survive for the moment)
hi Bill, seems there was a bugfix that solved it for you https://bugs.launchpad.net/openobject-addons/+bug/1179893. Would you mind to post a short how-to here how to get that in play? Best it would be dummy-proof I guess.