[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.

Manual forward port of 577eb10c0b .
This commit is contained in:
Thibault Delavallée
2017-06-13 12:30:14 +02:00
parent aae12c2bad
commit 6baa42ed57
2 changed files with 11 additions and 1 deletions
+5 -1
View File
@@ -552,7 +552,11 @@ class ResourceCalendar(models.Model):
def plan_hours(self, hours, day_dt, compute_leaves=False, resource_id=None):
""" Return datetime after having planned hours """
res = self._schedule_hours(hours, day_dt, compute_leaves, resource_id)
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_days(self, days, day_dt, compute_leaves=False, resource_id=None):
+6
View File
@@ -276,6 +276,9 @@ class ResourceWorkingHours(TestResourceCommon):
td += item[1] - item[0]
self.assertEqual(td.total_seconds() / 3600.0, 40.0)
res = self.calendar.plan_hours(-40, day_dt=Datetime.from_string('2013-02-12 09:00:00'))
self.assertEqual(res, Datetime.from_string('2013-01-29 09:00:00'))
def test_calendar_hours_scheduling_forward(self):
res = self.calendar._schedule_hours(40, day_dt=Datetime.from_string('2013-02-12 09:00:00'))
self.assertEqual(res[0][:2], (Datetime.from_string('2013-02-12 09:00:00'), Datetime.from_string('2013-02-12 16:00:00')))
@@ -291,6 +294,9 @@ class ResourceWorkingHours(TestResourceCommon):
td += item[1] - item[0]
self.assertEqual(td.total_seconds() / 3600.0, 40.0)
res = self.calendar.plan_hours(40, day_dt=Datetime.from_string('2013-02-12 09:00:00'))
self.assertEqual(res, Datetime.from_string('2013-02-26 09:00:00'))
def test_calendar_hours_scheduling_forward_leaves_resource(self):
res = self.calendar._schedule_hours(
40, day_dt=Datetime.from_string('2013-02-12 09:00:00'),