Moved can_refund logic to CourseEnrollment
This commit is contained in:
@@ -26,6 +26,7 @@ from django.dispatch import receiver
|
||||
import django.dispatch
|
||||
from django.forms import ModelForm, forms
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
import comment_client as cc
|
||||
from pytz import UTC
|
||||
|
||||
@@ -926,6 +927,18 @@ class CourseEnrollment(models.Model):
|
||||
self.is_active = False
|
||||
self.save()
|
||||
|
||||
def refundable(self):
|
||||
"""
|
||||
For paid/verified certificates, students may receive a refund IFF they have
|
||||
a verified certificate and the deadline for refunds has not yet passed.
|
||||
"""
|
||||
course_mode = CourseMode.mode_for_course(self.course_id, 'verified')
|
||||
if course_mode is None:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
|
||||
class CourseEnrollmentAllowed(models.Model):
|
||||
"""
|
||||
|
||||
@@ -256,6 +256,22 @@ class DashboardTest(TestCase):
|
||||
self.assertFalse(course_mode_info['show_upsell'])
|
||||
self.assertIsNone(course_mode_info['days_for_upsell'])
|
||||
|
||||
def test_refundable(self):
|
||||
verified_mode = CourseModeFactory.create(
|
||||
course_id=self.course.id,
|
||||
mode_slug='verified',
|
||||
mode_display_name='Verified',
|
||||
expiration_date=(datetime.now(pytz.UTC) + timedelta(days=1)).date()
|
||||
)
|
||||
enrollment = CourseEnrollment.enroll(self.user, self.course.id, mode='verified')
|
||||
|
||||
self.assertTrue(enrollment.refundable())
|
||||
|
||||
verified_mode.expiration_date = (datetime.now(pytz.UTC) - timedelta(days=1)).date()
|
||||
verified_mode.save()
|
||||
self.assertFalse(enrollment.refundable())
|
||||
|
||||
|
||||
|
||||
class EnrollInCourseTest(TestCase):
|
||||
"""Tests enrolling and unenrolling in courses."""
|
||||
|
||||
@@ -48,7 +48,6 @@ from student.forms import PasswordResetFormNoActive
|
||||
|
||||
from verify_student.models import SoftwareSecurePhotoVerification
|
||||
from certificates.models import CertificateStatuses, certificate_status_for_student
|
||||
from shoppingcart.models import CertificateItem
|
||||
|
||||
from xmodule.course_module import CourseDescriptor
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError
|
||||
@@ -341,7 +340,7 @@ def dashboard(request):
|
||||
verification_status, verification_msg = SoftwareSecurePhotoVerification.user_status(user)
|
||||
|
||||
show_refund_option_for = frozenset(course.id for course, _enrollment in courses
|
||||
if (has_access(request.user, course, 'refund') and (_enrollment.mode == "verified")))
|
||||
if _enrollment.refundable())
|
||||
|
||||
# get info w.r.t ExternalAuthMap
|
||||
external_auth_map = None
|
||||
|
||||
Reference in New Issue
Block a user