From bc0986f53bc03bb958f3acce10ec23805afb7b6a Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 19 Oct 2015 11:47:31 +0200 Subject: [PATCH] [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 --- addons/hr_timesheet_sheet/hr_timesheet_sheet.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index f8984fd4a28..876a871e488 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -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')]