From 2cbda9172f1e69362f14ec527dbac8b23ac3565f Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Sat, 2 Apr 2016 20:11:31 +1100 Subject: [PATCH] Fixes bug in product and category, and ceiling enabling conditions --- registrasion/controllers/conditions.py | 6 +++--- registrasion/tests/test_cart.py | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/registrasion/controllers/conditions.py b/registrasion/controllers/conditions.py index 63362a28..7243737a 100644 --- a/registrasion/controllers/conditions.py +++ b/registrasion/controllers/conditions.py @@ -158,7 +158,7 @@ class CategoryConditionController(ConditionController): category=self.condition.enabling_category, ) products_count = rego.ProductItem.objects.filter( - cart=carts, + cart__in=carts, product__in=enabling_products, ).count() return products_count > 0 @@ -177,7 +177,7 @@ class ProductConditionController(ConditionController): carts = rego.Cart.objects.filter(user=user, released=False) products_count = rego.ProductItem.objects.filter( - cart=carts, + cart__in=carts, product__in=self.condition.enabling_products.all(), ).count() return products_count > 0 @@ -247,7 +247,7 @@ class TimeOrStockLimitConditionController(ConditionController): product_items = rego.ProductItem.objects.filter( product__in=self._products().all(), ) - product_items = product_items.filter(cart=reserved_carts) + product_items = product_items.filter(cart__in=reserved_carts) count = product_items.aggregate(Sum("quantity"))["quantity__sum"] or 0 diff --git a/registrasion/tests/test_cart.py b/registrasion/tests/test_cart.py index bc58d5fb..c203c9b7 100644 --- a/registrasion/tests/test_cart.py +++ b/registrasion/tests/test_cart.py @@ -72,6 +72,15 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase): cls.PROD_4.price = Decimal("5.00") cls.PROD_4.save() + # Burn through some carts -- this made some past EC tests fail + current_cart = CartController.for_user(cls.USER_1) + current_cart.cart.active = False + current_cart.cart.save() + + current_cart = CartController.for_user(cls.USER_2) + current_cart.cart.active = False + current_cart.cart.save() + @classmethod def make_ceiling(cls, name, limit=None, start_time=None, end_time=None): limit_ceiling = rego.TimeOrStockLimitEnablingCondition.objects.create(