Merge pull request #24413 from edx/feanil/shoppingcart-removal-instructor-analytics
DEPR-43 - Remove shopping cart from instructor analytics.
This commit is contained in:
@@ -1056,37 +1056,6 @@ def get_grading_config(request, course_id):
|
||||
return JsonResponse(response_payload)
|
||||
|
||||
|
||||
@ensure_csrf_cookie
|
||||
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
|
||||
@require_course_permission(permissions.CAN_RESEARCH)
|
||||
def get_sale_records(request, course_id, csv=False): # pylint: disable=redefined-outer-name
|
||||
"""
|
||||
return the summary of all sales records for a particular course
|
||||
"""
|
||||
course_id = CourseKey.from_string(course_id)
|
||||
query_features = [
|
||||
'company_name', 'company_contact_name', 'company_contact_email', 'total_codes', 'total_used_codes',
|
||||
'total_amount', 'created', 'customer_reference_number', 'recipient_name', 'recipient_email', 'created_by',
|
||||
'internal_reference', 'invoice_number', 'codes', 'course_id'
|
||||
]
|
||||
|
||||
sale_data = instructor_analytics.basic.sale_record_features(course_id, query_features)
|
||||
|
||||
if not csv:
|
||||
for item in sale_data:
|
||||
item['created_by'] = item['created_by'].username
|
||||
|
||||
response_payload = {
|
||||
'course_id': text_type(course_id),
|
||||
'sale': sale_data,
|
||||
'queried_features': query_features
|
||||
}
|
||||
return JsonResponse(response_payload)
|
||||
else:
|
||||
header, datarows = instructor_analytics.csvs.format_dictlist(sale_data, query_features)
|
||||
return instructor_analytics.csvs.create_csv_response("e-commerce_sale_invoice_records.csv", header, datarows)
|
||||
|
||||
|
||||
@transaction.non_atomic_requests
|
||||
@ensure_csrf_cookie
|
||||
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
|
||||
|
||||
@@ -308,11 +308,6 @@ def _section_e_commerce(course, access, paid_mode, coupons_enabled, reports_enab
|
||||
'sale_validation_url': reverse('sale_validation', kwargs={'course_id': six.text_type(course_key)}),
|
||||
'ajax_update_coupon': reverse('update_coupon', kwargs={'course_id': six.text_type(course_key)}),
|
||||
'ajax_add_coupon': reverse('add_coupon', kwargs={'course_id': six.text_type(course_key)}),
|
||||
'get_sale_records_url': reverse('get_sale_records', kwargs={'course_id': six.text_type(course_key)}),
|
||||
'get_sale_order_records_url': reverse(
|
||||
'get_sale_order_records',
|
||||
kwargs={'course_id': six.text_type(course_key)}
|
||||
),
|
||||
'instructor_url': reverse('instructor_dashboard', kwargs={'course_id': six.text_type(course_key)}),
|
||||
'get_registration_code_csv_url': reverse(
|
||||
'get_registration_codes',
|
||||
|
||||
@@ -27,13 +27,6 @@ from lms.djangoapps.grades.api import context as grades_context
|
||||
from lms.djangoapps.verify_student.services import IDVerificationService
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
from openedx.core.djangolib.markup import HTML, Text
|
||||
from shoppingcart.models import (
|
||||
CouponRedemption,
|
||||
CourseRegCodeItem,
|
||||
CourseRegistrationCodeInvoiceItem,
|
||||
PaidCourseRegistration,
|
||||
RegistrationCodeRedemption
|
||||
)
|
||||
from student.models import CourseEnrollment, CourseEnrollmentAllowed
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -63,130 +56,6 @@ CERTIFICATE_FEATURES = ('course_id', 'mode', 'status', 'grade', 'created_date',
|
||||
UNAVAILABLE = "[unavailable]"
|
||||
|
||||
|
||||
def sale_order_record_features(course_id, features):
|
||||
"""
|
||||
Return list of sale orders features as dictionaries.
|
||||
|
||||
sales_records(course_id, ['company_name, total_codes', total_amount])
|
||||
would return [
|
||||
{'company_name': 'group_A', 'total_codes': '1', total_amount:'total_amount1 in decimal'.}
|
||||
{'company_name': 'group_B', 'total_codes': '2', total_amount:'total_amount2 in decimal'.}
|
||||
{'company_name': 'group_C', 'total_codes': '3', total_amount:'total_amount3 in decimal'.}
|
||||
]
|
||||
"""
|
||||
purchased_courses = PaidCourseRegistration.objects.filter(
|
||||
Q(course_id=course_id),
|
||||
Q(status='purchased') | Q(status='refunded')
|
||||
).order_by('order')
|
||||
|
||||
purchased_course_reg_codes = CourseRegCodeItem.objects.filter(
|
||||
Q(course_id=course_id),
|
||||
Q(status='purchased') | Q(status='refunded')
|
||||
).order_by('order')
|
||||
|
||||
def sale_order_info(purchased_course, features):
|
||||
"""
|
||||
convert purchase transactions to dictionary
|
||||
"""
|
||||
|
||||
sale_order_features = [x for x in SALE_ORDER_FEATURES if x in features]
|
||||
order_item_features = [x for x in ORDER_ITEM_FEATURES if x in features]
|
||||
|
||||
# Extracting order information
|
||||
sale_order_dict = dict((feature, getattr(purchased_course.order, feature))
|
||||
for feature in sale_order_features)
|
||||
|
||||
quantity = int(purchased_course.qty)
|
||||
unit_cost = float(purchased_course.unit_cost)
|
||||
sale_order_dict.update({"quantity": quantity})
|
||||
sale_order_dict.update({"total_amount": quantity * unit_cost})
|
||||
|
||||
sale_order_dict.update({"logged_in_username": purchased_course.order.user.username})
|
||||
sale_order_dict.update({"logged_in_email": purchased_course.order.user.email})
|
||||
|
||||
# Extracting OrderItem information of unit_cost, list_price and status
|
||||
order_item_dict = dict((feature, getattr(purchased_course, feature, None))
|
||||
for feature in order_item_features)
|
||||
|
||||
order_item_dict['list_price'] = purchased_course.get_list_price()
|
||||
|
||||
sale_order_dict.update(
|
||||
{"total_discount": (order_item_dict['list_price'] - order_item_dict['unit_cost']) * quantity}
|
||||
)
|
||||
|
||||
order_item_dict.update({"coupon_code": 'N/A'})
|
||||
|
||||
coupon_redemption = CouponRedemption.objects.select_related('coupon').filter(order_id=purchased_course.order_id)
|
||||
# if coupon is redeemed against the order, update the information in the order_item_dict
|
||||
if coupon_redemption.exists():
|
||||
coupon_codes = [redemption.coupon.code for redemption in coupon_redemption]
|
||||
order_item_dict.update({'coupon_code': ", ".join(coupon_codes)})
|
||||
|
||||
sale_order_dict.update(dict(list(order_item_dict.items())))
|
||||
|
||||
return sale_order_dict
|
||||
|
||||
csv_data = [sale_order_info(purchased_course, features) for purchased_course in purchased_courses]
|
||||
csv_data.extend(
|
||||
[sale_order_info(purchased_course_reg_code, features)
|
||||
for purchased_course_reg_code in purchased_course_reg_codes]
|
||||
)
|
||||
return csv_data
|
||||
|
||||
|
||||
def sale_record_features(course_id, features):
|
||||
"""
|
||||
Return list of sales features as dictionaries.
|
||||
|
||||
sales_records(course_id, ['company_name, total_codes', total_amount])
|
||||
would return [
|
||||
{'company_name': 'group_A', 'total_codes': '1', total_amount:'total_amount1 in decimal'.}
|
||||
{'company_name': 'group_B', 'total_codes': '2', total_amount:'total_amount2 in decimal'.}
|
||||
{'company_name': 'group_C', 'total_codes': '3', total_amount:'total_amount3 in decimal'.}
|
||||
]
|
||||
"""
|
||||
sales = CourseRegistrationCodeInvoiceItem.objects.select_related('invoice').filter(course_id=course_id)
|
||||
|
||||
def sale_records_info(sale, features):
|
||||
"""
|
||||
Convert sales records to dictionary
|
||||
|
||||
"""
|
||||
invoice = sale.invoice
|
||||
sale_features = [x for x in SALE_FEATURES if x in features]
|
||||
course_reg_features = [x for x in COURSE_REGISTRATION_FEATURES if x in features]
|
||||
|
||||
# Extracting sale information
|
||||
sale_dict = dict((feature, getattr(invoice, feature))
|
||||
for feature in sale_features)
|
||||
|
||||
total_used_codes = RegistrationCodeRedemption.objects.filter(
|
||||
registration_code__in=sale.courseregistrationcode_set.all()
|
||||
).count()
|
||||
sale_dict.update({"invoice_number": invoice.id})
|
||||
sale_dict.update({"total_codes": sale.courseregistrationcode_set.all().count()})
|
||||
sale_dict.update({'total_used_codes': total_used_codes})
|
||||
|
||||
codes = [reg_code.code for reg_code in sale.courseregistrationcode_set.all()]
|
||||
|
||||
# Extracting registration code information
|
||||
if len(codes) > 0:
|
||||
obj_course_reg_code = sale.courseregistrationcode_set.all()[:1].get()
|
||||
course_reg_dict = dict((feature, getattr(obj_course_reg_code, feature))
|
||||
for feature in course_reg_features)
|
||||
else:
|
||||
course_reg_dict = dict((feature, None)
|
||||
for feature in course_reg_features)
|
||||
|
||||
course_reg_dict['course_id'] = text_type(course_id)
|
||||
course_reg_dict.update({'codes': ", ".join(codes)})
|
||||
sale_dict.update(dict(list(course_reg_dict.items())))
|
||||
|
||||
return sale_dict
|
||||
|
||||
return [sale_records_info(sale, features) for sale in sales]
|
||||
|
||||
|
||||
def issued_certificates(course_key, features):
|
||||
"""
|
||||
Return list of issued certificates as dictionaries against the given course key.
|
||||
|
||||
@@ -33,8 +33,6 @@ from lms.djangoapps.instructor_analytics.basic import (
|
||||
get_response_state,
|
||||
list_may_enroll,
|
||||
list_problem_responses,
|
||||
sale_order_record_features,
|
||||
sale_record_features
|
||||
)
|
||||
from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory
|
||||
from student.models import CourseEnrollment, CourseEnrollmentAllowed
|
||||
|
||||
Reference in New Issue
Block a user