Fix appointment slot interval and selection

This commit is contained in:
metatroncubeswdev 2026-09-01 00:50:21 -04:00
parent 0595267a8c
commit 7ac21f361b
2 changed files with 18 additions and 6 deletions

View File

@ -40,9 +40,9 @@ class McsAppointmentType(models.Model):
) )
slot_step = fields.Float( slot_step = fields.Float(
string="Slot Step", string="Slot Step",
default=0.5, default=1.0,
required=True, 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( min_schedule_hours = fields.Float(
string="Minimum Notice", string="Minimum Notice",
@ -145,8 +145,8 @@ class McsAppointmentType(models.Model):
day_end = self._localize(day, 23.99) day_end = self._localize(day, 23.99)
busy_intervals = self._busy_intervals(day_start, day_end) busy_intervals = self._busy_intervals(day_start, day_end)
slots = [] slots = []
step = timedelta(hours=self.slot_step)
duration = timedelta(hours=self.duration) duration = timedelta(hours=self.duration)
step = max(timedelta(hours=self.slot_step), duration)
for attendance in attendances.sorted("hour_from"): for attendance in attendances.sorted("hour_from"):
cursor = self._localize(day, attendance.hour_from) cursor = self._localize(day, attendance.hour_from)
end_limit = self._localize(day, attendance.hour_to) end_limit = self._localize(day, attendance.hour_to)

View File

@ -2,6 +2,10 @@
"use strict"; "use strict";
function initAppointmentBooking(root) { function initAppointmentBooking(root) {
if (root.dataset.mcsAppointmentReady === "1") {
return;
}
const startInput = root.querySelector(".js-mcs-start"); const startInput = root.querySelector(".js-mcs-start");
const stopInput = root.querySelector(".js-mcs-stop"); const stopInput = root.querySelector(".js-mcs-stop");
const selectedLabel = root.querySelector(".js-mcs-selected-slot"); const selectedLabel = root.querySelector(".js-mcs-selected-slot");
@ -11,8 +15,10 @@
return; return;
} }
root.dataset.mcsAppointmentReady = "1";
buttons.forEach((button) => { buttons.forEach((button) => {
button.addEventListener("click", () => { button.addEventListener("click", (ev) => {
ev.preventDefault();
buttons.forEach((item) => item.classList.remove("active")); buttons.forEach((item) => item.classList.remove("active"));
button.classList.add("active"); button.classList.add("active");
startInput.value = button.dataset.start || ""; startInput.value = button.dataset.start || "";
@ -22,7 +28,13 @@
}); });
} }
document.addEventListener("DOMContentLoaded", () => { function initAllAppointmentBookings() {
document.querySelectorAll(".mcs-appointment").forEach(initAppointmentBooking); document.querySelectorAll(".mcs-appointment").forEach(initAppointmentBooking);
}); }
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initAllAppointmentBookings);
} else {
initAllAppointmentBookings();
}
})(); })();