forked from CGM_Public/pretix_original
Fixed bug in quota calculation (thanks @rixx!)
This commit is contained in:
@@ -527,6 +527,7 @@ class Quota(LoggedModel):
|
||||
return Voucher.objects.filter(
|
||||
Q(block_quota=True) &
|
||||
Q(redeemed=False) &
|
||||
Q(Q(valid_until__isnull=True) | Q(valid_until__gte=now())) &
|
||||
Q(Q(self._position_lookup) | Q(quota=self))
|
||||
).distinct().count()
|
||||
|
||||
|
||||
@@ -214,6 +214,22 @@ class QuotaTestCase(BaseQuotaTestCase):
|
||||
v.save()
|
||||
self.assertEqual(self.var1.check_quotas(), (Quota.AVAILABILITY_ORDERED, 0))
|
||||
|
||||
def test_voucher_quota_expiring_soon(self):
|
||||
self.quota.variations.add(self.var1)
|
||||
self.quota.size = 1
|
||||
self.quota.save()
|
||||
Voucher.objects.create(quota=self.quota, event=self.event, valid_until=now() + timedelta(days=5),
|
||||
block_quota=True)
|
||||
self.assertEqual(self.var1.check_quotas(), (Quota.AVAILABILITY_ORDERED, 0))
|
||||
|
||||
def test_voucher_quota_expired(self):
|
||||
self.quota.variations.add(self.var1)
|
||||
self.quota.size = 1
|
||||
self.quota.save()
|
||||
Voucher.objects.create(quota=self.quota, event=self.event, valid_until=now() - timedelta(days=5),
|
||||
block_quota=True)
|
||||
self.assertEqual(self.var1.check_quotas(), (Quota.AVAILABILITY_OK, 1))
|
||||
|
||||
|
||||
class OrderTestCase(BaseQuotaTestCase):
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user