From def6bced98532541eb31715f117e860c5a457cdd Mon Sep 17 00:00:00 2001 From: Emma Green Date: Thu, 17 Oct 2019 12:54:36 -0400 Subject: [PATCH] move the anonymous check earlier so that it cannot error out when it expects a non-anonymous user --- openedx/features/discounts/applicability.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openedx/features/discounts/applicability.py b/openedx/features/discounts/applicability.py index 310bf3a34b..7d151da091 100644 --- a/openedx/features/discounts/applicability.py +++ b/openedx/features/discounts/applicability.py @@ -89,6 +89,10 @@ def can_receive_discount(user, course, discount_expiration_date=None): # TODO: Add additional conditions to return False here + # anonymous users should never get the discount + if user.is_anonymous: + return False + # Check if discount has expired if not discount_expiration_date: discount_expiration_date = get_discount_expiration_date(user, course) @@ -113,9 +117,6 @@ def can_receive_discount(user, course, discount_expiration_date=None): if DiscountRestrictionConfig.disabled_for_course_stacked_config(course): return False - if user.is_anonymous: - return False - # Don't allow users who have enrolled in any courses in non-upsellable # modes if CourseEnrollment.objects.filter(user=user).exclude(mode__in=CourseMode.UPSELL_TO_VERIFIED_MODES).exists():