diff --git a/addons/resource/models/resource.py b/addons/resource/models/resource.py index e1050d4a5a2..16c0a8dac42 100644 --- a/addons/resource/models/resource.py +++ b/addons/resource/models/resource.py @@ -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)