api: factorize booking filter in recurring events fillslots (#78084)

This commit is contained in:
Valentin Deniaud 2023-06-15 12:34:16 +02:00
parent 00ad7b0747
commit f28cd4d104
1 changed files with 6 additions and 8 deletions

View File

@ -1737,19 +1737,17 @@ class RecurringFillslots(APIView):
)
events_to_book = events_to_book.exclude(has_overlap=True)
existing_bookings = Booking.objects.filter(
event__in=events_to_book, user_external_id=user_external_id
).values('event')
# outdated bookings to remove (cancelled bookings to replace by an active booking)
events_cancelled_to_delete = events_to_book.filter(
booking__user_external_id=user_external_id,
booking__cancellation_datetime__isnull=False,
full=False,
pk__in=existing_bookings.filter(cancellation_datetime__isnull=False), full=False
)
# book only events without active booking for the user
events_to_book = events_to_book.exclude(
pk__in=Booking.objects.filter(
event__in=events_to_book,
user_external_id=user_external_id,
cancellation_datetime__isnull=True,
).values('event')
pk__in=existing_bookings.filter(cancellation_datetime__isnull=True)
)
# exclude full events