[FIX] hr_timesheet_sheet: week number according to ISO 8601

The ISO weekday should be computed with isocalendar dateformat
The exact directive is '%V' according to GNU/Linux system strftime
http://man7.org/linux/man-pages/man3/strftime.3.html

However '%V' is not documented in official cross-platform syntax supported on
all python built, according to standardized by ANSI C formats
https://docs.python.org/2.7/library/datetime.html#strftime-and-strptime-behavior

as '%V' may not be supported on other platforms such as MS Windows, use the
cross-platform 'isoformat()' method.

Note that according to ISO 8601, the start and end of date may belong to the
previous or next year.
e.g.
>>> datetime.datetime.strptime('2005-01-01', '%Y-%m-%d').isocalendar()
(2004, 53, 6)
>>> datetime.datetime.strptime('2005-01-01', '%Y-%m-%d').strftime('%W')
'00'

Fixes #8927
This commit is contained in:
Martin Trigaux
2015-10-19 12:25:39 +02:00
parent 102b337c6a
commit bc0986f53b
@@ -218,7 +218,8 @@ class hr_timesheet_sheet(osv.osv):
return []
if isinstance(ids, (long, int)):
ids = [ids]
return [(r['id'], _('Week ')+datetime.strptime(r['date_from'], '%Y-%m-%d').strftime('%U')) \
# week number according to ISO 8601 Calendar
return [(r['id'], _('Week ')+str(datetime.strptime(r['date_from'], '%Y-%m-%d').isocalendar()[1])) \
for r in self.read(cr, uid, ids, ['date_from'],
context=context, load='_classic_write')]