Fixes bug where discount quantity applied to all users rather than specific user. Adds test case.
This commit is contained in:
parent
83b11cd722
commit
8e6364d02a
3 changed files with 17 additions and 0 deletions
|
@ -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"))
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue