summaryrefslogtreecommitdiff
path: root/addons/resource
diff options
context:
space:
mode:
authorWilliam Henrotin <whe@odoo.com>2018-08-21 17:16:40 +0200
committerWilliam Henrotin <whe@odoo.com>2018-08-22 16:02:52 +0200
commit701d0f0e1ab708d26ce08d806d5f8fef200ff7ff (patch)
treeb37e00a43034d4f6a73f24588eeb930bd3993dfd /addons/resource
parent5fdee3ddbb8f3e69bcf1ecc8dec193975054acc5 (diff)
[FIX] resource: allow to plan 0 hours
The method `plan_hours` does nothing if the `hours` parameter is equal to 0. This commit adds the 0 case in the logic, and add an optional `resource` in the parameters. Example: A workorder works each days between 8am and 4pm. If we call `plan_hours(0)` at 9pm, we want to get 8am the next day. Currently, it sends back 9pm. Before this commit, a hack existed consisting to send a very small value to `plan_hours`. The holidays and non-working time were taken into account and the result was rounded to the second. We can now send explicitely 0 and the non-working hours will be skipped.
Diffstat (limited to 'addons/resource')
-rw-r--r--addons/resource/models/resource.py12
-rw-r--r--addons/resource/tests/test_resource.py8
2 files changed, 9 insertions, 11 deletions
diff --git a/addons/resource/models/resource.py b/addons/resource/models/resource.py
index bd42f1b1e99..35d1e2cd9b4 100644
--- a/addons/resource/models/resource.py
+++ b/addons/resource/models/resource.py
@@ -295,7 +295,7 @@ class ResourceCalendar(models.Model):
)
@api.multi
- def plan_hours(self, hours, day_dt, compute_leaves=False, domain=None):
+ def plan_hours(self, hours, day_dt, compute_leaves=False, domain=None, resource=None):
"""
`compute_leaves` controls whether or not this method is taking into
account the global leaves.
@@ -309,11 +309,11 @@ class ResourceCalendar(models.Model):
# which method to use for retrieving intervals
if compute_leaves:
- get_intervals = partial(self._work_intervals, domain=domain)
+ get_intervals = partial(self._work_intervals, domain=domain, resource=resource)
else:
get_intervals = self._attendance_intervals
- if hours > 0:
+ if hours >= 0:
delta = timedelta(days=14)
for n in range(100):
dt = day_dt + delta * n
@@ -323,8 +323,7 @@ class ResourceCalendar(models.Model):
return revert(start + timedelta(hours=hours))
hours -= interval_hours
return False
-
- elif hours < 0:
+ else:
hours = abs(hours)
delta = timedelta(days=14)
for n in range(100):
@@ -336,9 +335,6 @@ class ResourceCalendar(models.Model):
hours -= interval_hours
return False
- else:
- return revert(day_dt)
-
@api.multi
def plan_days(self, days, day_dt, compute_leaves=False, domain=None):
"""
diff --git a/addons/resource/tests/test_resource.py b/addons/resource/tests/test_resource.py
index b7adce78f3e..2e12ba7b28a 100644
--- a/addons/resource/tests/test_resource.py
+++ b/addons/resource/tests/test_resource.py
@@ -260,9 +260,11 @@ class TestCalendar(TestResourceCommon):
time = self.calendar_jean.plan_hours(-10, datetime_tz(2018, 4, 10, 0, 0, 0, tzinfo=self.jean.tz), compute_leaves=True)
self.assertEqual(time, datetime_tz(2018, 4, 6, 14, 0, 0, tzinfo=self.jean.tz))
- # zero planning
- time = self.calendar_jean.plan_hours(0, datetime_tz(2018, 4, 10, 0, 0, 0, tzinfo=self.jean.tz), compute_leaves=True)
- self.assertEqual(time, datetime_tz(2018, 4, 10, 0, 0, 0, tzinfo=self.jean.tz))
+ # zero planning with holidays
+ time = self.calendar_jean.plan_hours(0, datetime_tz(2018, 4, 11, 0, 0, 0, tzinfo=self.jean.tz), compute_leaves=True)
+ self.assertEqual(time, datetime_tz(2018, 4, 12, 8, 0, 0, tzinfo=self.jean.tz))
+ time = self.calendar_jean.plan_hours(0, datetime_tz(2018, 4, 10, 0, 0, 0, tzinfo=self.jean.tz), compute_leaves=False)
+ self.assertEqual(time, datetime_tz(2018, 4, 10, 8, 0, 0, tzinfo=self.jean.tz))
# very small planning
time = self.calendar_jean.plan_hours(0.0002, datetime_tz(2018, 4, 10, 0, 0, 0, tzinfo=self.jean.tz), compute_leaves=True)