From 8724893d5619e9917243ecdec76acd8ce0d9bda2 Mon Sep 17 00:00:00 2001 From: Henrik Norlin Date: Thu, 1 Aug 2024 00:02:16 +0200 Subject: [PATCH 1/2] [IMP] resource_booking: get_intervals Now we can get intervals of an empty booking, by specifying the needed values, including the booking type. --- resource_booking/models/resource_booking.py | 11 ++++++----- .../models/resource_booking_combination.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/resource_booking/models/resource_booking.py b/resource_booking/models/resource_booking.py index 129843b5..552d4c05 100644 --- a/resource_booking/models/resource_booking.py +++ b/resource_booking/models/resource_booking.py @@ -624,7 +624,7 @@ def _get_available_slots(self, start_dt, end_dt): test_start += slot_duration return result - def _get_intervals(self, start_dt, end_dt, combination=None): + def _get_intervals(self, start_dt, end_dt, combination=None, type=None): """Get available intervals for this booking, based on the calendar of the booking type and the calendar(s) of the relevant resource combination(s).""" @@ -638,10 +638,11 @@ def _get_intervals(self, start_dt, end_dt, combination=None): analyzing_booking=booking_id, exclude_public_holidays=True ) # RBT calendar uses no resources to restrict bookings - if booking.type_id: - result = booking.type_id.resource_calendar_id._work_intervals_batch( - start_dt, end_dt - )[False] + if not type: + type = booking.type_id + if type and len(type) == 1: + r = type.resource_calendar_id._work_intervals_batch(start_dt, end_dt)[False] + result = r else: result = Intervals([]) # Restrict with the chosen combination, or to at least one of the diff --git a/resource_booking/models/resource_booking_combination.py b/resource_booking/models/resource_booking_combination.py index f8b3d390..c21ca8e6 100644 --- a/resource_booking/models/resource_booking_combination.py +++ b/resource_booking/models/resource_booking_combination.py @@ -87,7 +87,7 @@ def _get_intervals(self, start_dt, end_dt): if not combination_intervals: break # Can't restrict more calendar = combination.forced_calendar_id or res.calendar_id - # combination_intervals &= calendar._work_intervals(start_dt, end_dt, res) + # Get available intervals (see resource_calendar.py) combination_intervals &= calendar._work_intervals_batch( start_dt, end_dt, res )[res.id] From 4a1a3e77019772ae47701421e9eeea64d3c836a7 Mon Sep 17 00:00:00 2001 From: Henrik Norlin Date: Thu, 1 Aug 2024 00:08:04 +0200 Subject: [PATCH 2/2] [FIX] resource_booking: ows-cloud -> norlinhenrik --- resource_booking/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resource_booking/__manifest__.py b/resource_booking/__manifest__.py index 887d9639..219455b1 100644 --- a/resource_booking/__manifest__.py +++ b/resource_booking/__manifest__.py @@ -11,7 +11,7 @@ "category": "Appointments", "website": "https://github.com/OCA/calendar", "author": "Tecnativa, Odoo Community Association (OCA)", - "maintainers": ["pedrobaeza", "ows-cloud"], + "maintainers": ["pedrobaeza", "norlinhenrik"], "license": "AGPL-3", "application": True, "installable": True,