[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
This commit is contained in:
Antonio Espinosa 2015-08-24 14:36:57 +02:00 committed by Denis Ledoux
parent 416364fcca
commit e1d59f8f82
2 changed files with 4 additions and 4 deletions

View File

@ -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(

View File

@ -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,