feat: Add flag for AA-759 streak celebration discount experiment

AA-759
This commit is contained in:
Matthew Piatetsky
2021-05-03 16:57:06 -04:00
parent 4a0731ce61
commit 9c5992521a
11 changed files with 218 additions and 36 deletions

View File

@@ -19,6 +19,7 @@ from edx_toggles.toggles import LegacyWaffleFlag, LegacyWaffleFlagNamespace
from common.djangoapps.course_modes.models import CourseMode
from common.djangoapps.entitlements.models import CourseEntitlement
from lms.djangoapps.courseware.utils import is_mode_upsellable
from lms.djangoapps.experiments.models import ExperimentData
from lms.djangoapps.experiments.stable_bucketing import stable_bucketing_hash_group
from openedx.features.discounts.models import DiscountPercentageConfig, DiscountRestrictionConfig
@@ -82,6 +83,41 @@ def get_discount_expiration_date(user, course):
return discount_expiration_date
def can_show_streak_discount_experiment_coupon(user, course):
"""
Check whether this combination of user and course
can receive the AA-759 experiment discount.
"""
# Course end date needs to be in the future
if course.has_ended():
return False
# Course needs to have a non-expired verified mode
modes_dict = CourseMode.modes_for_course_dict(course=course, include_expired=False)
if 'verified' not in modes_dict:
return False
# Learner needs to be in an upgradeable mode
try:
enrollment = CourseEnrollment.objects.get(
user=user,
course=course.id,
)
except CourseEnrollment.DoesNotExist:
return False
if not is_mode_upsellable(user, enrollment):
return False
# We can't import this at Django load time within the openedx tests settings context
from openedx.features.enterprise_support.utils import is_enterprise_learner
# Don't give discount to enterprise users
if is_enterprise_learner(user):
return False
return True
def can_receive_discount(user, course, discount_expiration_date=None):
"""
Check all the business logic about whether this combination of user and course