api: fix waiting list condition in RecurringFillslots (#55905)
This commit is contained in:
parent
7f4c9d96df
commit
2d5a9bfd73
|
@ -1606,7 +1606,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(),
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue