Fixed bug in quota calculation (thanks @rixx!)

This commit is contained in:
Raphael Michel
2016-08-04 18:00:28 +02:00
parent 17d5221579
commit 58e706b721
2 changed files with 17 additions and 0 deletions

View File

@@ -527,6 +527,7 @@ class Quota(LoggedModel):
return Voucher.objects.filter( return Voucher.objects.filter(
Q(block_quota=True) & Q(block_quota=True) &
Q(redeemed=False) & Q(redeemed=False) &
Q(Q(valid_until__isnull=True) | Q(valid_until__gte=now())) &
Q(Q(self._position_lookup) | Q(quota=self)) Q(Q(self._position_lookup) | Q(quota=self))
).distinct().count() ).distinct().count()

View File

@@ -214,6 +214,22 @@ class QuotaTestCase(BaseQuotaTestCase):
v.save() v.save()
self.assertEqual(self.var1.check_quotas(), (Quota.AVAILABILITY_ORDERED, 0)) 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): class OrderTestCase(BaseQuotaTestCase):
def setUp(self): def setUp(self):