svthalia / sagexit

A stripped down Django reservation system using SAML

Home Page:https://reservations.thalia.nu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Room occupation not computed properly during capacity check

JobDoesburg opened this issue · comments

capacity_reached = (
Reservation.objects.filter(room=room)
.filter(
Q(start_time__lte=start_time, end_time__gt=start_time)
| Q(start_time__lt=end_time, end_time__gte=end_time)
| Q(start_time__gte=start_time, end_time__lte=end_time)
)
.exclude(pk=pk)
.count()
>= Room.objects.get(id=room).capacity
)

Currently we count all overlapping reservations when adding a new reservation. However, it is very well possible that in total the amount of overlapping reservations exceeds 6 when some reservations take longer others take shorter. We should count the overlapping reservations that all overlap with each other (so 10:00-12:00 and 12:00-14:00 both overlap with 10:00-14:00, but in the capacity computation, they should count as 1).