diff --git a/registrasion/controllers/cart.py b/registrasion/controllers/cart.py index 59b308ed..d9307b39 100644 --- a/registrasion/controllers/cart.py +++ b/registrasion/controllers/cart.py @@ -211,6 +211,7 @@ class CartController(object): # Get the count of past uses of this discount condition # as this affects the total amount we're allowed to use now. past_uses = rego.DiscountItem.objects.filter( + cart__user=self.cart.user, discount=discount.discount, ) agg = past_uses.aggregate(Sum("quantity")) diff --git a/registrasion/tests/test_cart.py b/registrasion/tests/test_cart.py index c65011b9..d000b946 100644 --- a/registrasion/tests/test_cart.py +++ b/registrasion/tests/test_cart.py @@ -37,6 +37,7 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase): description="This is a test category", order=10, render_type=rego.Category.RENDER_TYPE_RADIO, + required=False, ) cls.CAT_1.save() @@ -45,6 +46,7 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase): description="This is a test category", order=10, render_type=rego.Category.RENDER_TYPE_RADIO, + required=False, ) cls.CAT_2.save() diff --git a/registrasion/tests/test_discount.py b/registrasion/tests/test_discount.py index 5d325eff..6f943d0f 100644 --- a/registrasion/tests/test_discount.py +++ b/registrasion/tests/test_discount.py @@ -200,3 +200,17 @@ class DiscountTestCase(RegistrationCartTestCase): # There is one discount, and it should apply to the more expensive. self.assertEqual(1, len(discount_items)) self.assertEqual(self.PROD_3, discount_items[0].product) + + def test_discount_quantity_is_per_user(self): + self.add_discount_prod_1_includes_cat_2(quantity=1) + + # Both users should be able to apply the same discount + # in the same way + for user in (self.USER_1, self.USER_2): + cart = CartController.for_user(user) + cart.add_to_cart(self.PROD_1, 1) # Enable the discount + cart.add_to_cart(self.PROD_3, 1) + + discount_items = list(cart.cart.discountitem_set.all()) + # The discount is applied. + self.assertEqual(1, len(discount_items))