Skip to content

Commit

Permalink
Voucher form: Fix quota check for partially redeemed vouchers
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Nov 29, 2023
1 parent b92feb3 commit 82704b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/pretix/control/forms/vouchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def clean(self):
cnt = len(data['codes']) * data.get('max_usages', 0)
else:
cnt = data.get('max_usages', 0)
if self.instance and self.instance.pk:
cnt -= self.instance.redeemed # these do not need quota any more

Voucher.clean_item_properties(
data, self.instance.event,
Expand Down
13 changes: 13 additions & 0 deletions src/tests/control/test_vouchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,19 @@ def test_change_voucher_validity_to_valid_quota_full(self):
v.refresh_from_db()
assert v.valid_until < now()

def test_change_voucher_validity_to_valid_quota_full_already_redeemed(self):
self.quota_tickets.size = 1
self.quota_tickets.save()
with scopes_disabled():
v = self.event.vouchers.create(item=self.ticket, valid_until=now() - datetime.timedelta(days=3),
block_quota=True, redeemed=1, max_usages=2)
self._change_voucher(v, {
'valid_until_0': (now() + datetime.timedelta(days=3)).strftime('%Y-%m-%d'),
'valid_until_1': (now() + datetime.timedelta(days=3)).strftime('%H:%M:%S')
})
v.refresh_from_db()
assert v.valid_until > now()

def test_change_voucher_validity_to_valid_quota_free(self):
with scopes_disabled():
v = self.event.vouchers.create(item=self.ticket, valid_until=now() - datetime.timedelta(days=3),
Expand Down

0 comments on commit 82704b6

Please sign in to comment.