Commit f0474519 by Vedran Karačić Committed by GitHub

Merge pull request #845 from edx/vkaracic/SOL-1821

[SOL-1821] Set redemption count for single use vouchers to 1 if used.
parents 6a27460b 16978ad7
......@@ -459,6 +459,26 @@ class UtilTests(CouponMixin, CourseCatalogMockMixin, CourseCatalogTestMixin, Lms
new_basket = self.apply_voucher(self.user, self.site, voucher)
self.assertEqual(len(new_basket.applied_offers()), 0)
def test_single_use_redemption_count(self):
"""Verify redemption count does not increment for other, unused, single-use vouchers."""
coupon = self.create_coupon(
title='Test single use',
catalog=self.catalog,
quantity=2
)
coupon.history.all().update(history_user=self.user)
vouchers = coupon.attr.coupon_vouchers.vouchers.all()
self.use_voucher('TEST', vouchers[0], self.user)
__, rows = generate_coupon_report([coupon.attr.coupon_vouchers])
# rows[0] - first voucher header row
# rows[1] - first voucher row with usage information
# rows[2] - second voucher header row
self.assertEqual(len(rows), 3)
self.assertEqual(rows[0]['Redemption Count'], 1)
self.assertEqual(rows[1]['Redeemed By Username'], self.user.username)
self.assertEqual(rows[2]['Redemption Count'], 0)
def test_generate_coupon_report_for_used_query_coupon(self):
"""Test that used query coupon voucher reports which course was it used for."""
catalog_query = '*:*'
......
......@@ -119,12 +119,14 @@ def _get_info_for_coupon_report(coupon, voucher):
category_names = ''
# Set the max_uses_count for single-use vouchers to 1,
# for other usage limitations (once per customer and multi-use in the future)
# for other usage limitations (once per customer and multi-use)
# which don't have the max global applications limit set,
# set the max_uses_count to 10000 which is the arbitrary limit Oscar sets:
# https://github.com/django-oscar/django-oscar/blob/master/src/oscar/apps/offer/abstract_models.py#L253
redemption_count = offer.num_applications
if voucher.usage == Voucher.SINGLE_USE:
max_uses_count = 1
redemption_count = voucher.num_orders
elif voucher.usage != Voucher.SINGLE_USE and offer.max_global_applications is None:
max_uses_count = 10000
else:
......@@ -147,7 +149,7 @@ def _get_info_for_coupon_report(coupon, voucher):
'Coupon Start Date': voucher.start_datetime.strftime("%b %d, %y"),
'Coupon Expiry Date': voucher.end_datetime.strftime("%b %d, %y"),
'Maximum Coupon Usage': max_uses_count,
'Redemption Count': offer.num_applications,
'Redemption Count': redemption_count,
}
if course_id:
......
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