diff --git a/addons/mcs_appointment_booking/models/appointment_type.py b/addons/mcs_appointment_booking/models/appointment_type.py index 671c8c3..dc8a05e 100644 --- a/addons/mcs_appointment_booking/models/appointment_type.py +++ b/addons/mcs_appointment_booking/models/appointment_type.py @@ -40,9 +40,9 @@ class McsAppointmentType(models.Model): ) slot_step = fields.Float( string="Slot Step", - default=0.5, + default=1.0, required=True, - help="Distance between proposed slots in hours.", + help="Distance between proposed slots in hours. Public slots never overlap the appointment duration.", ) min_schedule_hours = fields.Float( string="Minimum Notice", @@ -145,8 +145,8 @@ class McsAppointmentType(models.Model): day_end = self._localize(day, 23.99) busy_intervals = self._busy_intervals(day_start, day_end) slots = [] - step = timedelta(hours=self.slot_step) duration = timedelta(hours=self.duration) + step = max(timedelta(hours=self.slot_step), duration) for attendance in attendances.sorted("hour_from"): cursor = self._localize(day, attendance.hour_from) end_limit = self._localize(day, attendance.hour_to) diff --git a/addons/mcs_appointment_booking/static/src/js/appointment_booking.js b/addons/mcs_appointment_booking/static/src/js/appointment_booking.js index dd6a64a..379751e 100644 --- a/addons/mcs_appointment_booking/static/src/js/appointment_booking.js +++ b/addons/mcs_appointment_booking/static/src/js/appointment_booking.js @@ -2,6 +2,10 @@ "use strict"; function initAppointmentBooking(root) { + if (root.dataset.mcsAppointmentReady === "1") { + return; + } + const startInput = root.querySelector(".js-mcs-start"); const stopInput = root.querySelector(".js-mcs-stop"); const selectedLabel = root.querySelector(".js-mcs-selected-slot"); @@ -11,8 +15,10 @@ return; } + root.dataset.mcsAppointmentReady = "1"; buttons.forEach((button) => { - button.addEventListener("click", () => { + button.addEventListener("click", (ev) => { + ev.preventDefault(); buttons.forEach((item) => item.classList.remove("active")); button.classList.add("active"); startInput.value = button.dataset.start || ""; @@ -22,7 +28,13 @@ }); } - document.addEventListener("DOMContentLoaded", () => { + function initAllAppointmentBookings() { document.querySelectorAll(".mcs-appointment").forEach(initAppointmentBooking); - }); + } + + if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", initAllAppointmentBookings); + } else { + initAllAppointmentBookings(); + } })();