mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
Resolved two more edge cases in quota handling
Scenario 1) Blocking voucher is used in a CartPosition. Previously too much was subtracted from the quota. Scenario 2) When two quotas are assigned to a product and one of them is sold out, blocking vouchers for the other quota should not enable to buy the product.
This commit is contained in:
@@ -554,6 +554,10 @@ class Quota(LoggedModel):
|
||||
|
||||
return CartPosition.objects.filter(
|
||||
Q(expires__gte=now()) &
|
||||
~Q(
|
||||
Q(voucher__isnull=False) & Q(voucher__block_quota=True)
|
||||
& Q(Q(voucher__valid_until__isnull=True) | Q(voucher__valid_until__gte=now()))
|
||||
) &
|
||||
self._position_lookup
|
||||
).distinct().count()
|
||||
|
||||
|
||||
@@ -222,8 +222,13 @@ def _check_positions(event: Event, dt: datetime, positions: List[CartPosition]):
|
||||
|
||||
quota_ok = True
|
||||
|
||||
if not cp.voucher or not (cp.voucher.allow_ignore_quota or cp.voucher.block_quota):
|
||||
ignore_all_quotas = cp.expires >= dt or (
|
||||
cp.voucher and (cp.voucher.allow_ignore_quota or (cp.voucher.block_quota and cp.voucher.quota is None)))
|
||||
|
||||
if not ignore_all_quotas:
|
||||
for quota in quotas:
|
||||
if cp.voucher and cp.voucher.block_quota and cp.voucher.quota_id == quota.pk:
|
||||
continue
|
||||
avail = quota.availability()
|
||||
if avail[0] != Quota.AVAILABILITY_OK:
|
||||
# This quota is sold out/currently unavailable, so do not sell this at all
|
||||
|
||||
Reference in New Issue
Block a user