Skip to content
Snippets Groups Projects
Commit 20687f95 authored by Feanil Patel's avatar Feanil Patel
Browse files

DEPR-43 Remove shoppingcart certs refs.

There's a chance that the whole management command should be removed since we
don't do change modes with the command anymore but that's a different problem
for a different day I think.
parent 10ab6399
Branches
Tags
No related merge requests found
......@@ -10,7 +10,6 @@ from django.db import transaction
from opaque_keys.edx.keys import CourseKey
from six import text_type
from shoppingcart.models import CertificateItem
from student.models import CourseEnrollment
from track.management.tracked_command import TrackedCommand
......@@ -43,9 +42,6 @@ class Command(TrackedCommand):
dest='dest_course_list',
required=True,
help='the new course(s) to enroll the student into')
parser.add_argument('-c', '--transfer-certificates',
action='store_true',
help='try to transfer certificate items to the new course')
@transaction.atomic
def handle(self, *args, **options):
......@@ -54,9 +50,6 @@ class Command(TrackedCommand):
for course_key in options['dest_course_list']:
dest_keys.append(CourseKey.from_string(course_key))
if options['transfer_certificates'] and len(dest_keys) > 1:
raise TransferStudentError('Cannot transfer certificate items from one course to many.')
source_students = User.objects.filter(
courseenrollment__course_id=source_key
)
......@@ -89,38 +82,3 @@ class Command(TrackedCommand):
# form the old course.
if not old_is_active:
new_enrollment.update_enrollment(is_active=False, skip_refund=True)
if options['transfer_certificates']:
self._transfer_certificate_item(source_key, enrollment, user, dest_keys, new_enrollment)
@staticmethod
def _transfer_certificate_item(source_key, enrollment, user, dest_keys, new_enrollment):
"""
Transfer the certificate item from one course to another.
Do not use this generally, since certificate items are directly associated with a particular purchase.
This should only be used when a single course to a new location. This cannot be used when transferring
from one course to many.
Args:
source_key (str): The course key string representation for the original course.
enrollment (CourseEnrollment): The original enrollment to move the certificate item from.
user (User): The user to transfer the item for.
dest_keys (list): A list of course key strings to transfer the item to.
new_enrollment (CourseEnrollment): The new enrollment to associate the certificate item with.
Returns:
None
"""
try:
certificate_item = CertificateItem.objects.get(
course_id=source_key,
course_enrollment=enrollment
)
except CertificateItem.DoesNotExist:
print('No certificate for {}'.format(user))
return
certificate_item.course_id = dest_keys[0]
certificate_item.course_enrollment = new_enrollment
......@@ -13,7 +13,6 @@ from opaque_keys.edx import locator
from six import text_type
from course_modes.models import CourseMode
from shoppingcart.models import CertificateItem, Order
from student.models import (
EVENT_NAME_ENROLLMENT_ACTIVATED,
EVENT_NAME_ENROLLMENT_DEACTIVATED,
......@@ -132,14 +131,6 @@ class TestTransferStudents(ModuleStoreTestCase):
self.assertEqual((mode, True), CourseEnrollment.enrollment_mode_for_user(student, new_course_one.id))
self.assertEqual((mode, True), CourseEnrollment.enrollment_mode_for_user(student, new_course_two.id))
# Confirm the student has not be refunded.
target_certs = CertificateItem.objects.filter(
course_id=course.id, user_id=student, status='purchased', mode=mode
)
self.assertTrue(target_certs[0])
self.assertFalse(target_certs[0].refund_requested_time)
self.assertEqual(target_certs[0].order.status, 'purchased')
def _create_course(self, course_location):
"""
Creates a course
......@@ -159,7 +150,3 @@ class TestTransferStudents(ModuleStoreTestCase):
mode_display_name='verified cert',
min_price=50)
course_mode.save()
# When there is no expiration date on a verified mode, the user can always get a refund
cart = Order.get_cart_for_user(user=student)
CertificateItem.add_to_order(cart, course_id, 50, 'verified')
cart.purchase()
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