Widget: Respect order_max of voucher (#5167)

* Widget: Respect order_max of voucher

* fix tests, make voucher.max_usages explicit

---------

Co-authored-by: Richard Schreiber <schreiber@rami.io>
This commit is contained in:
Raphael Michel
2025-05-28 13:21:21 +02:00
committed by GitHub
parent 72b39932b7
commit c10e96795f
2 changed files with 6 additions and 4 deletions

View File

@@ -293,6 +293,8 @@ def get_grouped_items(event, *, channel: SalesChannel, subevent=None, voucher=No
max_per_order = sys.maxsize
else:
max_per_order = item.max_per_order or int(event.settings.max_items_per_order)
if voucher:
max_per_order = min(max_per_order, voucher.max_usages - voucher.redeemed)
if item.hidden_if_available:
q = item.hidden_if_available.availability(_cache=quota_cache)

View File

@@ -367,7 +367,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
def test_product_list_view_with_voucher(self):
with scopes_disabled():
self.event.vouchers.create(item=self.ticket, code="ABCDE")
self.event.vouchers.create(item=self.ticket, code="ABCDE", max_usages=1)
response = self.client.get('/%s/%s/widget/product_list?voucher=ABCDE' % (self.orga.slug, self.event.slug))
assert response['Access-Control-Allow-Origin'] == '*'
data = json.loads(response.content.decode())
@@ -410,7 +410,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
"free_price": False,
"original_price": None,
"name": "Early-bird ticket",
"order_max": 4
"order_max": 1
},
],
"description": None,
@@ -426,7 +426,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
def test_product_list_view_with_voucher_variation_through_quota(self):
with scopes_disabled():
self.event.vouchers.create(quota=self.quota_shirts, code="ABCDE")
self.event.vouchers.create(quota=self.quota_shirts, code="ABCDE", max_usages=1)
self.quota_shirts.variations.remove(self.shirt_blue)
response = self.client.get('/%s/%s/widget/product_list?voucher=ABCDE' % (self.orga.slug, self.event.slug))
assert response['Access-Control-Allow-Origin'] == '*'
@@ -474,7 +474,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
{
'id': self.shirt_red.pk,
'value': 'Red',
'order_max': 2,
'order_max': 1,
'description': None,
'original_price': None,
'price': {