agendas: fix counting of unlocked bookings with respect to waiting lists (#89266)
gitea/chrono/pipeline/head This commit looks good Details

This commit is contained in:
Benjamin Dauvergne 2024-04-08 17:24:41 +02:00
parent 7c91b91d89
commit 5fa96e62a8
2 changed files with 82 additions and 1 deletions

View File

@ -2495,13 +2495,15 @@ class Event(WithInspectMixin, models.Model):
'booking',
filter=Q(
booking__cancellation_datetime__isnull=True,
booking__in_waiting_list=False,
)
& ~Q(booking__lease__lock_code=lock_code),
),
unlocked_booked_waiting_list_places=Count(
'booking',
filter=Q(
booking__cancellation_datetime__isnull=False,
booking__cancellation_datetime__isnull=True,
booking__in_waiting_list=True,
)
& ~Q(booking__lease__lock_code=lock_code),
),

View File

@ -859,3 +859,82 @@ def test_api_events_fillslots_with_lock_code_expiration(app, user, freezer):
assert response.json['data'][0]['places']['reserved'] == 0
assert response.json['data'][1]['places']['available'] == 2
assert response.json['data'][1]['places']['reserved'] == 0
def test_waitin_list_places_using_lock_code(app, user, freezer):
agenda = build_event_agenda(
events={
'Event 1': {
'start_datetime': now() + datetime.timedelta(days=1),
'places': 2,
'waiting_list_places': 3,
}
}
)
# setup authorization
app.authorization = ('Basic', ('john.doe', 'password'))
# list events
resp = app.get(agenda.get_datetimes_url())
slot = resp.json['data'][0]
assert slot['places']['available'] == 2
assert slot['places']['full'] is False
# book first one
fillslot_url = slot['api']['fillslot_url']
datas = [app.post_json(fillslot_url, params={'lock_code': f'MYLOCK{i}'}).json for i in range(4)]
assert all(data['err'] == 0 for data in datas), 'Not all responses are ok'
# cancel second booking (in main list)
resp = app.post_json(datas[1]['api']['cancel_url'])
assert resp.json['err'] == 0
# cancel fourth booking (in waiting list)
resp = app.post_json(datas[3]['api']['cancel_url'])
assert resp.json['err'] == 0
# list events without lock code
resp = app.get(agenda.get_datetimes_url())
places = resp.json['data'][0]['places']
assert places == {
'total': 2,
'reserved': 1,
'available': 1,
'full': False,
'has_waiting_list': True,
'waiting_list_total': 3,
'waiting_list_reserved': 1,
'waiting_list_available': 2,
'waiting_list_activated': True,
}
# list events with lock code of first booking (in main list)
resp = app.get(agenda.get_datetimes_url(), params={'lock_code': 'MYLOCK0', 'hide_disabled': 'true'})
places = resp.json['data'][0]['places']
assert places == {
'total': 2,
'reserved': 0,
'available': 2,
'full': False,
'has_waiting_list': True,
'waiting_list_total': 3,
'waiting_list_reserved': 1,
'waiting_list_available': 2,
'waiting_list_activated': True,
}
# list events with lock code of third booking (in waiting list)
resp = app.get(agenda.get_datetimes_url(), params={'lock_code': 'MYLOCK2', 'hide_disabled': 'true'})
places = resp.json['data'][0]['places']
assert places == {
'total': 2,
'reserved': 1,
'available': 1,
'full': False,
'has_waiting_list': True,
'waiting_list_total': 3,
'waiting_list_reserved': 0,
'waiting_list_available': 3,
'waiting_list_activated': False,
}