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:
Raphael Michel
2016-08-15 22:53:32 +02:00
parent fddd612a63
commit 63b683096b
5 changed files with 132 additions and 1 deletions

View File

@@ -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()

View File

@@ -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