[IMP] resource: add the false key to work intervals batch

The False key is always added in attendance and leave intervals batch
but is not added in the work_intervals batch.

To give a more smooth API, this commit aligns work_intervals behavior
with the two other methods behavior, regarding the added False key.

Furthermore, we avoid to deal with a resource_list of two empty
recordsets, in the case where the resources parameter is None or empty
recordset.

PR: #77362

task-2646630
This commit is contained in:
Thibault Libioulle
2021-11-30 12:20:31 +01:00
parent e81788f877
commit 6d41b7ec7e
+17 -9
View File
@@ -382,13 +382,15 @@ class ResourceCalendar(models.Model):
""" Return the attendance intervals in the given datetime range.
The returned intervals are expressed in specified tz or in the resource's timezone.
"""
self.ensure_one()
resources = self.env['resource.resource'] if not resources else resources
assert start_dt.tzinfo and end_dt.tzinfo
self.ensure_one()
combine = datetime.combine
resources_list = list(resources) + [self.env['resource.resource']]
if not resources:
resources = self.env['resource.resource']
resources_list = [resources]
else:
resources_list = list(resources) + [self.env['resource.resource']]
resource_ids = [r.id for r in resources_list]
domain = domain if domain is not None else []
domain = expression.AND([domain, [
@@ -472,15 +474,18 @@ class ResourceCalendar(models.Model):
""" Return the leave intervals in the given datetime range.
The returned intervals are expressed in specified tz or in the calendar's timezone.
"""
resources = self.env['resource.resource'] if not resources else resources
assert start_dt.tzinfo and end_dt.tzinfo
self.ensure_one()
# for the computation, express all datetimes in UTC
resources_list = list(resources) + [self.env['resource.resource']]
if not resources:
resources = self.env['resource.resource']
resources_list = [resources]
else:
resources_list = list(resources) + [self.env['resource.resource']]
resource_ids = [r.id for r in resources_list]
if domain is None:
domain = [('time_type', '=', 'leave')]
# for the computation, express all datetimes in UTC
domain = domain + [
('calendar_id', 'in', [False, self.id]),
('resource_id', 'in', resource_ids),
@@ -518,7 +523,7 @@ class ResourceCalendar(models.Model):
resources = self.env['resource.resource']
resources_list = [resources]
else:
resources_list = list(resources)
resources_list = list(resources) + [self.env['resource.resource']]
attendance_intervals = self._attendance_intervals_batch(start_dt, end_dt, resources, tz=tz)
if compute_leaves:
@@ -588,8 +593,11 @@ class ResourceCalendar(models.Model):
@return dict with hours of attendance in each day between `from_datetime` and `to_datetime`
"""
self.ensure_one()
resources = self.env['resource.resource'] if not resources else resources
resources_list = list(resources) + [self.env['resource.resource']]
if not resources:
resources = self.env['resource.resource']
resources_list = [resources]
else:
resources_list = list(resources) + [self.env['resource.resource']]
# total hours per day: retrieve attendances with one extra day margin,
# in order to compute the total hours on the first and last days
from_full = from_datetime - timedelta(days=1)