From 392937d9e15f57a06c0ab63df7fabebf8780889d Mon Sep 17 00:00:00 2001 From: Muhammad Shoaib Date: Mon, 18 May 2015 15:51:19 +0500 Subject: [PATCH] MAYN-68 fixed the bug, total credit card purchases amount does not include the bulk purchases. --- .../tests/views/test_instructor_dashboard.py | 32 +++++++++++++++++-- .../instructor/views/instructor_dashboard.py | 6 ++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py index 75ce7ad671..4182a9576c 100644 --- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py +++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py @@ -8,10 +8,10 @@ from django.core.urlresolvers import reverse from django.test.utils import override_settings from courseware.tests.helpers import LoginEnrollmentTestCase -from student.tests.factories import AdminFactory +from student.tests.factories import AdminFactory, UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from shoppingcart.models import PaidCourseRegistration +from shoppingcart.models import PaidCourseRegistration, Order, CourseRegCodeItem from course_modes.models import CourseMode from student.roles import CourseFinanceAdminRole @@ -151,3 +151,31 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase): # link to dashboard shown expected_message = self.get_dashboard_demographic_message() self.assertTrue(expected_message in response.content) + + def add_course_to_user_cart(self, cart, course_key): + """ + adding course to user cart + """ + reg_item = PaidCourseRegistration.add_to_order(cart, course_key) + return reg_item + + @patch.dict('django.conf.settings.FEATURES', {'ENABLE_PAID_COURSE_REGISTRATION': True}) + def test_total_credit_cart_sales_amount(self): + """ + Test to check the total amount for all the credit card purchases. + """ + student = UserFactory.create() + self.client.login(username=student.username, password="test") + student_cart = Order.get_cart_for_user(student) + item = self.add_course_to_user_cart(student_cart, self.course.id) + resp = self.client.post(reverse('shoppingcart.views.update_user_cart'), {'ItemId': item.id, 'qty': 4}) + self.assertEqual(resp.status_code, 200) + student_cart.purchase() + + self.client.login(username=self.instructor.username, password="test") + CourseFinanceAdminRole(self.course.id).add_users(self.instructor) + single_purchase_total = PaidCourseRegistration.get_total_amount_of_purchased_item(self.course.id) + bulk_purchase_total = CourseRegCodeItem.get_total_amount_of_purchased_item(self.course.id) + total_amount = single_purchase_total + bulk_purchase_total + response = self.client.get(self.url) + self.assertIn('{currency}{amount}'.format(currency='$', amount=total_amount), response.content) diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index 4399cc6dff..d48d847aa5 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -33,7 +33,7 @@ from courseware.courses import get_course_by_id, get_studio_url from django_comment_client.utils import has_forum_access from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR from student.models import CourseEnrollment -from shoppingcart.models import Coupon, PaidCourseRegistration +from shoppingcart.models import Coupon, PaidCourseRegistration, CourseRegCodeItem from course_modes.models import CourseMode, CourseModesArchive from student.roles import CourseFinanceAdminRole, CourseSalesAdminRole from certificates.models import CertificateGenerationConfiguration @@ -158,7 +158,9 @@ def _section_e_commerce(course, access, paid_mode, coupons_enabled): total_amount = None if access['finance_admin']: - total_amount = PaidCourseRegistration.get_total_amount_of_purchased_item(course_key) + single_purchase_total = PaidCourseRegistration.get_total_amount_of_purchased_item(course_key) + bulk_purchase_total = CourseRegCodeItem.get_total_amount_of_purchased_item(course_key) + total_amount = single_purchase_total + bulk_purchase_total section_data = { 'section_key': 'e-commerce',