OrderChangeManager: Deal with unlimited quotas correctly

This commit is contained in:
Raphael Michel
2016-09-26 14:13:33 +02:00
parent 2a8bbb9952
commit 68987970bf
2 changed files with 9 additions and 1 deletions

View File

@@ -457,7 +457,7 @@ class OrderChangeManager:
if diff <= 0: if diff <= 0:
continue continue
avail = quota.availability() avail = quota.availability()
if avail[0] != Quota.AVAILABILITY_OK or avail[1] < diff: if avail[0] != Quota.AVAILABILITY_OK or (avail[1] is not None and avail[1] < diff):
raise OrderError(self.error_messages['quota'].format(name=quota.name)) raise OrderError(self.error_messages['quota'].format(name=quota.name))
def _check_free_to_paid(self): def _check_free_to_paid(self):

View File

@@ -188,6 +188,14 @@ class OrderChangeManagerTests(TestCase):
def test_empty(self): def test_empty(self):
self.ocm.commit() self.ocm.commit()
def test_quota_unlimited(self):
q = self.event.quotas.create(name='Test', size=None)
q.items.add(self.shirt)
self.ocm.change_item(self.op1, self.shirt, None)
self.ocm.commit()
self.op1.refresh_from_db()
assert self.op1.item == self.shirt
def test_quota_full(self): def test_quota_full(self):
q = self.event.quotas.create(name='Test', size=0) q = self.event.quotas.create(name='Test', size=0)
q.items.add(self.shirt) q.items.add(self.shirt)