Fixed missing check for variation.active

This commit is contained in:
Raphael Michel
2016-09-25 20:54:40 +02:00
parent a8a9db19de
commit 2a8bbb9952
3 changed files with 13 additions and 2 deletions

View File

@@ -140,7 +140,7 @@ def _add_new_items(event: Event, items: List[dict],
if item.hide_without_voucher and (voucher is None or voucher.item is None or voucher.item.pk != item.pk): if item.hide_without_voucher and (voucher is None or voucher.item is None or voucher.item.pk != item.pk):
return error_messages['voucher_required'] return error_messages['voucher_required']
if len(quotas) == 0 or not item.is_available(): if len(quotas) == 0 or not item.is_available() or (variation and not variation.active):
err = err or error_messages['unavailable'] err = err or error_messages['unavailable']
continue continue

View File

@@ -185,7 +185,7 @@ def _check_positions(event: Event, now_dt: datetime, positions: List[CartPositio
voucherids = set() voucherids = set()
for i, cp in enumerate(positions): for i, cp in enumerate(positions):
if not cp.item.active: if not cp.item.active or (cp.variation and not cp.variation.active):
err = err or error_messages['unavailable'] err = err or error_messages['unavailable']
cp.delete() cp.delete()
continue continue

View File

@@ -117,6 +117,17 @@ class CartTest(CartTestMixin, TestCase):
self.assertIsNone(objs[0].variation) self.assertIsNone(objs[0].variation)
self.assertEqual(objs[0].price, 23) self.assertEqual(objs[0].price, 23)
def test_variation_inactive(self):
self.shirt_red.active = False
self.shirt_red.save()
response = self.client.post('/%s/%s/cart/add' % (self.orga.slug, self.event.slug), {
'variation_%d_%d' % (self.shirt.id, self.shirt_red.id): '1'
}, follow=True)
self.assertRedirects(response, '/%s/%s/' % (self.orga.slug, self.event.slug),
target_status_code=200)
objs = list(CartPosition.objects.filter(cart_id=self.session_key, event=self.event))
self.assertEqual(len(objs), 0)
def test_variation(self): def test_variation(self):
response = self.client.post('/%s/%s/cart/add' % (self.orga.slug, self.event.slug), { response = self.client.post('/%s/%s/cart/add' % (self.orga.slug, self.event.slug), {
'variation_%d_%d' % (self.shirt.id, self.shirt_red.id): '1' 'variation_%d_%d' % (self.shirt.id, self.shirt_red.id): '1'