diff options
| author | Kevin Baptiste <kba@odoo.com> | 2020-05-14 09:38:43 +0000 |
|---|---|---|
| committer | Kevin Baptiste <kba@odoo.com> | 2020-07-02 06:48:45 +0000 |
| commit | 71f719a61ea34252abdc9f1b2fb2caf8e62c7917 (patch) | |
| tree | a328fa530de044fbbabeca1c83400f8fe9511b59 /addons | |
| parent | d24de2554e24431f9241c12f7202d4c9960edca0 (diff) | |
[IMP] resource: move unavailable intervals on resource.calendar
The method `_get_unavailable_intervals` was only available on
`resource.resource`. It's now moved to the `resource.calendar`.
closes odoo/odoo#51311
Taskid: 2253893
Related: odoo/enterprise#10616
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/resource/models/resource.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/addons/resource/models/resource.py b/addons/resource/models/resource.py index 44d4c7babb9..69cc1168067 100644 --- a/addons/resource/models/resource.py +++ b/addons/resource/models/resource.py @@ -421,6 +421,18 @@ class ResourceCalendar(models.Model): return (self._attendance_intervals(start_dt, end_dt, resource, tz=tz) - self._leave_intervals(start_dt, end_dt, resource, domain, tz=tz)) + def _unavailable_intervals(self, start_dt, end_dt, resource=None, domain=None, tz=None): + """ Return the unavailable intervals between the given datetimes. """ + work_intervals = self._work_intervals(start_dt, end_dt, resource, domain, tz) + work_intervals = [(start, stop) for start, stop, meta in work_intervals] + # start + flatten(intervals) + end + work_intervals = [start_dt] + list(chain.from_iterable(work_intervals)) + [end_dt] + # put it back to UTC + work_intervals = list(map(lambda dt: dt.astimezone(utc), work_intervals)) + # pick groups of two + work_intervals = list(zip(work_intervals[0::2], work_intervals[1::2])) + return work_intervals + # -------------------------------------------------- # Private Methods / Helpers # -------------------------------------------------- @@ -801,15 +813,7 @@ class ResourceResource(models.Model): resource_mapping = {} for resource in self: calendar = resource.calendar_id - resource_work_intervals = calendar._work_intervals(start_datetime, end_datetime, resource) - resource_work_intervals = [(start, stop) for start, stop, meta in resource_work_intervals] - # start + flatten(intervals) + end - resource_work_intervals = [start_datetime] + list(chain.from_iterable(resource_work_intervals)) + [end_datetime] - # put it back to UTC - resource_work_intervals = list(map(lambda dt: dt.astimezone(utc), resource_work_intervals)) - # pick groups of two - resource_work_intervals = list(zip(resource_work_intervals[0::2], resource_work_intervals[1::2])) - resource_mapping[resource.id] = resource_work_intervals + resource_mapping[resource.id] = calendar._unavailable_intervals(start_datetime, end_datetime, resource) return resource_mapping |
