[FIX] resource: return correct date when planning hours

Planning hours can be done forwards or backwards. In first case the
returned datetime should be the last one aka the date when the job is
finished. In second case it should be the first one, aka the date when
the job begins. Those are the dates user want to know and manipulate when
programming working hours.
This commit is contained in:
Thibault Delavallée
2017-06-13 10:56:25 +02:00
parent 1dd3d36b48
commit 577eb10c0b
2 changed files with 16 additions and 1 deletions
+5 -1
View File
@@ -474,7 +474,11 @@ class ResourceCalendar(models.Model):
""" Wrapper on _schedule_hours: return the beginning/ending datetime of
an hours scheduling. """
res = self._schedule_hours(hours, day_dt, compute_leaves, resource_id, default_interval)
return res and res[0][0] or False
if res and hours < 0.0:
return res[0][0]
elif res:
return res[-1][1]
return False
@api.multi
def schedule_hours(self, hours, day_dt=None,
+11
View File
@@ -273,6 +273,9 @@ class TestResource(TestResourceCommon):
td += item[1] - item[0]
self.assertEqual(seconds(td) / 3600.0, 40.0, 'resource_calendar: wrong hours scheduling')
res = self.calendar.schedule_hours_get_date(-40, day_dt=self.date1.replace(minute=0, second=0))
self.assertEqual(res, Datetime.from_string('2013-01-29 09:00:00'))
# --------------------------------------------------
# Test2: schedule hours forward
# --------------------------------------------------
@@ -299,6 +302,9 @@ class TestResource(TestResourceCommon):
td += item[1] - item[0]
self.assertEqual(seconds(td) / 3600.0, 40.0, 'resource_calendar: wrong hours scheduling')
res = self.calendar.schedule_hours_get_date(40, day_dt=self.date1.replace(minute=0, second=0))
self.assertEqual(res, Datetime.from_string('2013-02-26 09:00:00'))
res = self.calendar.schedule_hours(
40, day_dt=self.date1.replace(minute=0, second=0),
compute_leaves=True, resource_id=self.resource1_id
@@ -401,6 +407,11 @@ class TestResource(TestResourceCommon):
# 7h30 -> 12h30 = 5 / 13h -> 14h = 1 / -> 6h
self.assertEqual(res, 6, 'resource_calendar: wrong get_working_hours computation')
def test_45_calendar_hours_scheduling_minutes(self):
""" Testing minutes computation in calendar hours scheduling """
res = self.calendar.schedule_hours_get_date(-39, day_dt=self.date1.replace(minute=25, second=20))
self.assertEqual(res, Datetime.from_string('2013-01-29 10:25:20'))
def test_50_calendar_schedule_days(self):
""" Testing calendar days scheduling """