From 16b6471cb16efa66c62d19b29760e57853d766a4 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 29 Jul 2021 17:48:03 +0200 Subject: [PATCH] api: fix waiting list condition in RecurringFillslots (#55905) --- chrono/api/views.py | 3 ++- tests/api/test_fillslot.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/chrono/api/views.py b/chrono/api/views.py index 17f1186..40b12a7 100644 --- a/chrono/api/views.py +++ b/chrono/api/views.py @@ -1607,7 +1607,8 @@ class RecurringFillslots(APIView): events_to_book = Event.annotate_queryset(events_to_book) events_to_book = events_to_book.annotate( in_waiting_list=ExpressionWrapper( - Q(booked_places_count__gte=F('places')), output_field=BooleanField() + Q(booked_places_count__gte=F('places')) | Q(waiting_list_count__gt=0), + output_field=BooleanField(), ) ) diff --git a/tests/api/test_fillslot.py b/tests/api/test_fillslot.py index 8052218..96b6679 100644 --- a/tests/api/test_fillslot.py +++ b/tests/api/test_fillslot.py @@ -2191,3 +2191,31 @@ def test_recurring_events_api_fillslots(app, user, freezer): resp = app.post_json(fillslots_url, params={'user_external_id': 'a', 'slots': 'a:1'}, status=400) assert resp.json['err'] == 1 assert resp.json['err_desc'] == 'event a is not bookable' + + +def test_recurring_events_api_fillslots_waiting_list(app, user, freezer): + freezer.move_to('2021-09-06 12:00') + agenda = Agenda.objects.create(label='Foo bar', kind='events') + event = Event.objects.create( + label='Event', + start_datetime=now(), + recurrence_days=[0], + places=2, + waiting_list_places=2, + agenda=agenda, + recurrence_end_date=now() + datetime.timedelta(days=30), + ) + event.create_all_recurrences() + app.authorization = ('Basic', ('john.doe', 'password')) + + # create bookings in waiting list + for recurrence in event.recurrences.all(): + Booking.objects.create(event=recurrence, in_waiting_list=True) + events = Event.annotate_queryset(Event.objects.filter(primary_event__isnull=False)) + assert events.filter(waiting_list_count=1).count() == 5 + + # check that new bookings are put in waiting list despite free slots on main list + params = {'user_external_id': 'user_id', 'slots': 'event:0'} + resp = app.post_json('/api/agenda/%s/recurring_fillslots/' % agenda.slug, params=params) + assert resp.json['booking_count'] == 5 + assert events.filter(waiting_list_count=2).count() == 5 -- 2.20.1