From e1d59f8f82b4b1af28d51b406abd44137d9a72be Mon Sep 17 00:00:00 2001 From: Antonio Espinosa Date: Mon, 24 Aug 2015 14:36:57 +0200 Subject: [PATCH] [FIX] resource: Schedule days backwards when days is negative number Regarding _schedule_days, similar thing was done in saas-6, @ fd5e7f2. When the argument `days` was negative, the returned intervals were wrong. Regarding `get_working_intervals_of_day`, calling this method without `default_interval` and calendar set crashed. Closes #8208 --- addons/resource/resource.py | 6 ++---- addons/resource/tests/test_resource.py | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/resource/resource.py b/addons/resource/resource.py index b16fd210593..67a287564e6 100644 --- a/addons/resource/resource.py +++ b/addons/resource/resource.py @@ -328,6 +328,7 @@ class resource_calendar(osv.osv): # no calendar: try to use the default_interval, then return directly if id is None: + working_interval = [] if default_interval: working_interval = (start_dt.replace(hour=default_interval[0], minute=0, second=0), start_dt.replace(hour=default_interval[1], minute=0, second=0)) intervals = self.interval_remove_leaves(working_interval, work_limits) @@ -528,10 +529,7 @@ class resource_calendar(osv.osv): intervals = [] planned_days = 0 iterations = 0 - if backwards: - current_datetime = day_date.replace(hour=23, minute=59, second=59) - else: - current_datetime = day_date.replace(hour=0, minute=0, second=0) + current_datetime = day_date.replace(hour=0, minute=0, second=0) while planned_days < days and iterations < 1000: working_intervals = self.get_working_intervals_of_day( diff --git a/addons/resource/tests/test_resource.py b/addons/resource/tests/test_resource.py index 0cecb9853e5..afa8ac08784 100644 --- a/addons/resource/tests/test_resource.py +++ b/addons/resource/tests/test_resource.py @@ -430,6 +430,8 @@ class TestResource(TestResourceCommon): res = self.resource_calendar.schedule_days_get_date(cr, uid, self.calendar_id, 5, day_date=self.date1) self.assertEqual(res.date(), datetime.strptime('2013-02-26 00:0:00', _format).date(), 'resource_calendar: wrong days scheduling') + res = self.resource_calendar.schedule_days_get_date(cr, uid, self.calendar_id, -2, day_date=self.date1) + self.assertEqual(res.date(), datetime.strptime('2013-02-08 00:00:00', _format).date(), 'resource_calendar: wrong days scheduling') res = self.resource_calendar.schedule_days_get_date( cr, uid, self.calendar_id, 5, day_date=self.date1,