Tests updated & minor environment notes for agents

This commit is contained in:
2026-02-28 12:36:47 +03:00
parent 411180e312
commit 7718f8ccfe
3 changed files with 53 additions and 21 deletions
+7 -3
View File
@@ -1,5 +1,6 @@
from datetime import timedelta
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers
@@ -21,16 +22,19 @@ def validate_booking_request(service, staff, start_time, end_time):
if expected_end != end_time:
raise serializers.ValidationError({"end_time": _("End time must match service duration")})
start_local = timezone.localtime(start_time)
end_local = timezone.localtime(end_time)
availability_qs = StaffAvailability.objects.filter(
staff=staff,
day_of_week=start_time.weekday(),
day_of_week=start_local.weekday(),
is_active=True,
)
if availability_qs.exists():
within_window = availability_qs.filter(
start_time__lte=start_time.time(),
end_time__gte=end_time.time(),
start_time__lte=start_local.time(),
end_time__gte=end_local.time(),
).exists()
if not within_window:
raise serializers.ValidationError({"start_time": _("Booking is outside staff availability")})