Commit 3fe34287 by Vedran Karačić Committed by GitHub

Merge pull request #927 from edx/vkaracic/SOL-2055

Fix condition for multi-offer coupons.
parents 4584a9de 790f5dbe
...@@ -106,7 +106,7 @@ class CouponMixin(object): ...@@ -106,7 +106,7 @@ class CouponMixin(object):
def create_coupon(self, title='Test coupon', price=100, client=None, partner=None, catalog=None, code='', def create_coupon(self, title='Test coupon', price=100, client=None, partner=None, catalog=None, code='',
benefit_value=100, note=None, max_uses=None, quantity=5, catalog_query=None, benefit_value=100, note=None, max_uses=None, quantity=5, catalog_query=None,
course_seat_types=None, email_domains=None): course_seat_types=None, email_domains=None, voucher_type=Voucher.SINGLE_USE):
"""Helper method for creating a coupon. """Helper method for creating a coupon.
Arguments: Arguments:
...@@ -141,7 +141,7 @@ class CouponMixin(object): ...@@ -141,7 +141,7 @@ class CouponMixin(object):
'code': code, 'code': code,
'quantity': quantity, 'quantity': quantity,
'start_datetime': datetime.date(2015, 1, 1), 'start_datetime': datetime.date(2015, 1, 1),
'voucher_type': Voucher.SINGLE_USE, 'voucher_type': voucher_type,
'categories': [self.category], 'categories': [self.category],
'note': note, 'note': note,
'max_uses': max_uses, 'max_uses': max_uses,
......
...@@ -135,22 +135,19 @@ class CouponViewSetTest(CouponMixin, CourseCatalogTestMixin, TestCase): ...@@ -135,22 +135,19 @@ class CouponViewSetTest(CouponMixin, CourseCatalogTestMixin, TestCase):
def test_creating_multi_offer_coupon(self): def test_creating_multi_offer_coupon(self):
"""Test the creation of a multi-offer coupon.""" """Test the creation of a multi-offer coupon."""
ordinary_max_uses = 1 ordinary_coupon = self.create_coupon(quantity=2)
ordinary_coupon = self.create_coupon(quantity=2, max_uses=ordinary_max_uses)
ordinary_coupon_vouchers = ordinary_coupon.attr.coupon_vouchers.vouchers.all() ordinary_coupon_vouchers = ordinary_coupon.attr.coupon_vouchers.vouchers.all()
self.assertEqual( self.assertEqual(
ordinary_coupon_vouchers[0].offers.first(), ordinary_coupon_vouchers[0].offers.first(),
ordinary_coupon_vouchers[1].offers.first() ordinary_coupon_vouchers[1].offers.first()
) )
self.assertEqual(ordinary_coupon_vouchers[0].offers.first().max_global_applications, ordinary_max_uses)
multi_offer_coupon = self.create_coupon(quantity=2, max_uses=2) multi_offer_coupon = self.create_coupon(quantity=2, voucher_type=Voucher.MULTI_USE)
multi_offer_coupon_vouchers = multi_offer_coupon.attr.coupon_vouchers.vouchers.all() multi_offer_coupon_vouchers = multi_offer_coupon.attr.coupon_vouchers.vouchers.all()
first_offer = multi_offer_coupon_vouchers[0].offers.first() first_offer = multi_offer_coupon_vouchers[0].offers.first()
second_offer = multi_offer_coupon_vouchers[1].offers.first() second_offer = multi_offer_coupon_vouchers[1].offers.first()
self.assertNotEqual(first_offer, second_offer) self.assertNotEqual(first_offer, second_offer)
self.assertEqual(first_offer.max_global_applications, second_offer.max_global_applications)
def test_custom_code_string(self): def test_custom_code_string(self):
"""Test creating a coupon with custom voucher code.""" """Test creating a coupon with custom voucher code."""
......
...@@ -423,7 +423,9 @@ def create_vouchers( ...@@ -423,7 +423,9 @@ def create_vouchers(
# offer because the usage is tied to the offer so that a usage on one voucher would # offer because the usage is tied to the offer so that a usage on one voucher would
# mean all vouchers will have their usage decreased by one, hence each voucher needs # mean all vouchers will have their usage decreased by one, hence each voucher needs
# its own offer to keep track of its own usages without interfering with others. # its own offer to keep track of its own usages without interfering with others.
multi_offer = True if quantity > 1 and max_uses > 1 else False multi_offer = True if (
voucher_type == Voucher.MULTI_USE or voucher_type == Voucher.ONCE_PER_CUSTOMER
) else False
num_of_offers = quantity if multi_offer else 1 num_of_offers = quantity if multi_offer else 1
for num in range(num_of_offers): for num in range(num_of_offers):
offer = _get_or_create_offer( offer = _get_or_create_offer(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment