diff --git a/common/djangoapps/entitlements/models.py b/common/djangoapps/entitlements/models.py index d55ab0e1bb17cf3271343a8d400d5af86b6b79f1..3fea5e07b545a3a30dfcf8128783a13727133e5a 100644 --- a/common/djangoapps/entitlements/models.py +++ b/common/djangoapps/entitlements/models.py @@ -71,6 +71,9 @@ class CourseEntitlementPolicy(models.Model): to by leaving and regaining their entitlement within policy.regain_period days from start date of the course or their redemption, whichever comes later, and the expiration period hasn't passed yet """ + if entitlement.expired_at: + return False + if entitlement.enrollment_course_run: if GeneratedCertificate.certificate_for_student( entitlement.user_id, entitlement.enrollment_course_run.course_id) is not None: @@ -87,6 +90,10 @@ class CourseEntitlementPolicy(models.Model): yet been redeemed (enrollment_course_run is NULL) and policy.refund_period has not yet passed, or if the entitlement has been redeemed, but the regain period hasn't passed yet. """ + # If the Entitlement is expired already it is not refundable + if entitlement.expired_at: + return False + # If there's no order number, it cannot be refunded if entitlement.order_number is None: return False @@ -109,7 +116,8 @@ class CourseEntitlementPolicy(models.Model): # This is < because a get_days_since_created of expiration_period means that that many days have passed, # which should then expire the entitlement return (entitlement.get_days_since_created() < self.expiration_period.days # pylint: disable=no-member - and not entitlement.enrollment_course_run) + and not entitlement.enrollment_course_run + and not entitlement.expired_at) def __unicode__(self): return u'Course Entitlement Policy: expiration_period: {}, refund_period: {}, regain_period: {}'\ diff --git a/common/djangoapps/entitlements/tests/test_models.py b/common/djangoapps/entitlements/tests/test_models.py index ec4f0e25e4425a59cbd75feac41364e30142a703..6548939fbf82b66a36a060a066d94516895f39a8 100644 --- a/common/djangoapps/entitlements/tests/test_models.py +++ b/common/djangoapps/entitlements/tests/test_models.py @@ -46,6 +46,10 @@ class TestModels(TestCase): assert entitlement.is_entitlement_redeemable() is False + entitlement = CourseEntitlementFactory.create(expired_at=datetime.now()) + + assert entitlement.is_entitlement_refundable() is False + def test_is_entitlement_refundable(self): """ Test that the entitlement is refundable when created now, and is not refundable when created 70 days @@ -83,6 +87,10 @@ class TestModels(TestCase): assert entitlement.is_entitlement_refundable() is True + entitlement = CourseEntitlementFactory.create(expired_at=datetime.now()) + + assert entitlement.is_entitlement_refundable() is False + def test_is_entitlement_regainable(self): """ Test that the entitlement is not expired when created now, and is expired when created20 days @@ -113,6 +121,10 @@ class TestModels(TestCase): assert entitlement.is_entitlement_regainable() is False + entitlement = CourseEntitlementFactory.create(expired_at=datetime.now()) + + assert entitlement.is_entitlement_regainable + def test_get_days_until_expiration(self): """ Test that the expiration period is always less than or equal to the policy expiration