fix combined valid and product check

This commit is contained in:
Richard Schreiber
2026-04-29 13:06:09 +02:00
parent 8c84b6c634
commit b318a17159
2 changed files with 9 additions and 14 deletions

View File

@@ -665,20 +665,15 @@ def _redeem_process(*, checkinlists, raw_barcode, answers_data, datetime, force,
# 3. Handle the "multiple options found" case: Except for the unlikely case of a secret being also a valid primary
# key on the same list, we're probably dealing with multiple linked_orderpositions or the ``addon_match`` case
# here and in the latter case need to figure out which add-on has the right product.
# here and need to figure out which op has the right product. This basically is a valid-for-checkin-test on every op.
if len(op_candidates) > 1:
today = now()
# when we have addons and non-addons, we need to match the product as well
match_product = any([op.addon_to for op in op_candidates]) and any([not op.addon_to for op in op_candidates])
op_candidates_matching_product = [
op for op in op_candidates
if (
(not op.valid_from or op.valid_from < today) and
(not op.valid_until or op.valid_until > today) and
(not match_product or (
(list_by_event[op.order.event_id].addon_match or op.secret == raw_barcode or legacy_url_support) and
(list_by_event[op.order.event_id].all_products or op.item_id in {i.pk for i in list_by_event[op.order.event_id].limit_products.all()})
))
(list_by_event[op.order.event_id].all_products or op.item_id in {i.pk for i in list_by_event[op.order.event_id].limit_products.all()})
)
]

View File

@@ -302,7 +302,7 @@ def test_by_medium(token_client, organizer, clist, event, order):
@pytest.mark.django_db
def test_by_medium_multiple_orderpositions(token_client, organizer, clist, event, order):
def test_by_medium_multiple_orderpositions(token_client, organizer, clist_all, event, order):
with scopes_disabled():
rm = ReusableMedium.objects.create(
type="barcode",
@@ -315,7 +315,7 @@ def test_by_medium_multiple_orderpositions(token_client, organizer, clist, event
rm.linked_orderpositions.add(op_item_other)
# multiple tickets are valid => no check-in
resp = _redeem(token_client, organizer, clist, "abcdef", {"source_type": "barcode"})
resp = _redeem(token_client, organizer, clist_all, "abcdef", {"source_type": "barcode"})
assert resp.status_code == 400
assert resp.data['status'] == 'error'
assert resp.data['reason'] == 'ambiguous'
@@ -327,18 +327,18 @@ def test_by_medium_multiple_orderpositions(token_client, organizer, clist, event
with freeze_time("2020-01-01 13:45:00"):
# multiple tickets are valid => no check-in
resp = _redeem(token_client, organizer, clist, "abcdef", {"source_type": "barcode"})
resp = _redeem(token_client, organizer, clist_all, "abcdef", {"source_type": "barcode"})
assert resp.status_code == 400
assert resp.data['status'] == 'error'
assert resp.data['reason'] == 'ambiguous'
with freeze_time("2020-01-01 10:45:00"):
resp = _redeem(token_client, organizer, clist, "abcdef", {"source_type": "barcode"})
resp = _redeem(token_client, organizer, clist_all, "abcdef", {"source_type": "barcode"})
assert resp.status_code == 201
assert resp.data['status'] == 'ok'
with freeze_time("2020-01-01 15:45:00"):
resp = _redeem(token_client, organizer, clist, "abcdef", {"source_type": "barcode"})
resp = _redeem(token_client, organizer, clist_all, "abcdef", {"source_type": "barcode"})
assert resp.status_code == 400
assert resp.data['status'] == 'error'
assert resp.data['reason'] == 'already_redeemed'
@@ -349,7 +349,7 @@ def test_by_medium_multiple_orderpositions(token_client, organizer, clist, event
op_item_first.save()
with freeze_time("2020-01-01 15:45:00"):
resp = _redeem(token_client, organizer, clist, "abcdef", {"source_type": "barcode"})
resp = _redeem(token_client, organizer, clist_all, "abcdef", {"source_type": "barcode"})
assert resp.status_code == 400
assert resp.data['status'] == 'error'
assert resp.data['reason'] == 'invalid_time'
@@ -360,7 +360,7 @@ def test_by_medium_multiple_orderpositions(token_client, organizer, clist, event
op_item_other.canceled = True
op_item_other.save()
resp = _redeem(token_client, organizer, clist, "abcdef", {"source_type": "barcode"})
resp = _redeem(token_client, organizer, clist_all, "abcdef", {"source_type": "barcode"})
assert resp.status_code == 400
assert resp.data['status'] == 'error'
assert resp.data['reason'] == 'canceled'