diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py index 535676a320..60adb472ae 100644 --- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py +++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py @@ -11,7 +11,9 @@ from courseware.tests.helpers import LoginEnrollmentTestCase from student.tests.factories import AdminFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory - +from shoppingcart.models import PaidCourseRegistration +from course_modes.models import CourseMode +from student.roles import CourseFinanceAdminRole class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase): """ @@ -24,9 +26,14 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase): """ self.course = CourseFactory.create() + self.course_mode = CourseMode(course_id=self.course.id, + mode_slug="honor", + mode_display_name="honor cert", + min_price=40) + self.course_mode.save() # Create instructor account - instructor = AdminFactory.create() - self.client.login(username=instructor.username, password="test") + self.instructor = AdminFactory.create() + self.client.login(username=self.instructor.username, password="test") # URL for instructor dash self.url = reverse('instructor_dashboard', kwargs={'course_id': self.course.id.to_deprecated_string()}) @@ -51,6 +58,26 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase): return 'Demographic data is now available in Example.'.format(unicode(self.course.id)) + def test_default_currency_in_the_html_response(self): + """ + Test that checks the default currency_symbol ($) in the response + """ + CourseFinanceAdminRole(self.course.id).add_users(self.instructor) + total_amount = PaidCourseRegistration.get_total_amount_of_purchased_item(self.course.id) + response = self.client.get(self.url) + self.assertTrue('${amount}'.format(amount=total_amount) in response.content) + + @override_settings(PAID_COURSE_REGISTRATION_CURRENCY=['PKR', 'Rs']) + def test_override_currency_settings_in_the_html_response(self): + """ + Test that checks the default currency_symbol ($) in the response + """ + CourseFinanceAdminRole(self.course.id).add_users(self.instructor) + total_amount = PaidCourseRegistration.get_total_amount_of_purchased_item(self.course.id) + response = self.client.get(self.url) + self.assertTrue('{currency}{amount}'.format(currency='Rs', amount=total_amount) in response.content) + + @patch.dict(settings.FEATURES, {'DISPLAY_ANALYTICS_ENROLLMENTS': False}) @override_settings(ANALYTICS_DASHBOARD_URL='') def test_no_enrollments(self): diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index f8176c9ce0..1f6429d28e 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -1137,6 +1137,7 @@ def generate_registration_codes(request, course_id): 'sale_price': sale_price, 'quantity': quantity, 'registration_codes': registration_codes, + 'currency_symbol': settings.PAID_COURSE_REGISTRATION_CURRENCY[1], 'course_url': course_url, 'platform_name': microsite.get_value('platform_name', settings.PLATFORM_NAME), 'dashboard_url': dashboard_url, diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index 6c97199ac3..95a9b116ea 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -144,6 +144,7 @@ def _section_e_commerce(course, access): 'section_display_name': _('E-Commerce'), 'access': access, 'course_id': course_key.to_deprecated_string(), + 'currency_symbol': settings.PAID_COURSE_REGISTRATION_CURRENCY[1], 'ajax_remove_coupon_url': reverse('remove_coupon', kwargs={'course_id': course_key.to_deprecated_string()}), 'ajax_get_coupon_info': reverse('get_coupon_info', kwargs={'course_id': course_key.to_deprecated_string()}), 'get_user_invoice_preference_url': reverse('get_user_invoice_preference', kwargs={'course_id': course_key.to_deprecated_string()}), diff --git a/lms/djangoapps/shoppingcart/models.py b/lms/djangoapps/shoppingcart/models.py index db5eee15db..360bcb8a25 100644 --- a/lms/djangoapps/shoppingcart/models.py +++ b/lms/djangoapps/shoppingcart/models.py @@ -309,6 +309,7 @@ class Order(models.Model): 'order_items': orderitems, 'course_names': ", ".join([course_info[0] for course_info in courses_info]), 'dashboard_url': dashboard_url, + 'currency_symbol': settings.PAID_COURSE_REGISTRATION_CURRENCY[1], 'order_placed_by': '{username} ({email})'.format(username=self.user.username, email=getattr(self.user, 'email')), # pylint: disable=E1101 'has_billing_info': settings.FEATURES['STORE_BILLING_INFO'], 'platform_name': microsite.get_value('platform_name', settings.PLATFORM_NAME), diff --git a/lms/djangoapps/shoppingcart/tests/test_views.py b/lms/djangoapps/shoppingcart/tests/test_views.py index 96db9e0e51..923bd98057 100644 --- a/lms/djangoapps/shoppingcart/tests/test_views.py +++ b/lms/djangoapps/shoppingcart/tests/test_views.py @@ -136,6 +136,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase): resp = self.client.post(reverse('shoppingcart.views.add_course_to_cart', args=[self.course_key.to_deprecated_string()])) self.assertEqual(resp.status_code, 403) + @patch('shoppingcart.views.render_to_response', render_mock) def test_billing_details(self): billing_url = reverse('billing_details') self.login_user() @@ -150,6 +151,13 @@ class ShoppingCartViewsTests(ModuleStoreTestCase): resp = self.client.get(billing_url) self.assertEqual(resp.status_code, 200) + ((template, context), _) = render_mock.call_args # pylint: disable=W0621 + self.assertEqual(template, 'shoppingcart/billing_details.html') + # check for the default currency in the context + self.assertEqual(context['currency'], 'usd') + self.assertEqual(context['currency_symbol'], '$') + + data = {'company_name': 'Test Company', 'company_contact_name': 'JohnDoe', 'company_contact_email': 'john@est.com', 'recipient_name': 'Mocker', 'recipient_email': 'mock@germ.com', 'company_address_line_1': 'DC Street # 1', @@ -160,6 +168,24 @@ class ShoppingCartViewsTests(ModuleStoreTestCase): resp = self.client.post(billing_url, data) self.assertEqual(resp.status_code, 200) + @patch('shoppingcart.views.render_to_response', render_mock) + @override_settings(PAID_COURSE_REGISTRATION_CURRENCY=['PKR', 'Rs']) + def test_billing_details_with_override_currency_settings(self): + billing_url = reverse('billing_details') + self.login_user() + + #chagne the order_type to business + self.cart.order_type = 'business' + self.cart.save() + resp = self.client.get(billing_url) + self.assertEqual(resp.status_code, 200) + + ((template, context), _) = render_mock.call_args # pylint: disable=W0621 + self.assertEqual(template, 'shoppingcart/billing_details.html') + # check for the override currency settings in the context + self.assertEqual(context['currency'], 'PKR') + self.assertEqual(context['currency_symbol'], 'Rs') + def test_add_course_to_cart_already_in_cart(self): PaidCourseRegistration.add_to_order(self.cart, self.course_key) self.login_user() @@ -655,6 +681,28 @@ class ShoppingCartViewsTests(ModuleStoreTestCase): self.assertEqual(len(context['shoppingcart_items']), 2) self.assertEqual(context['amount'], 80) self.assertIn("80.00", context['form_html']) + # check for the default currency in the context + self.assertEqual(context['currency'], 'usd') + self.assertEqual(context['currency_symbol'], '$') + + @patch('shoppingcart.views.render_purchase_form_html', form_mock) + @patch('shoppingcart.views.render_to_response', render_mock) + @override_settings(PAID_COURSE_REGISTRATION_CURRENCY=['PKR', 'Rs']) + def test_show_cart_with_override_currency_settings(self): + self.login_user() + reg_item = PaidCourseRegistration.add_to_order(self.cart, self.course_key) + resp = self.client.get(reverse('shoppingcart.views.show_cart', args=[])) + self.assertEqual(resp.status_code, 200) + + ((purchase_form_arg_cart,), _) = form_mock.call_args # pylint: disable=W0621 + purchase_form_arg_cart_items = purchase_form_arg_cart.orderitem_set.all().select_subclasses() + self.assertIn(reg_item, purchase_form_arg_cart_items) + + ((template, context), _) = render_mock.call_args + self.assertEqual(template, 'shoppingcart/shopping_cart.html') + # check for the override currency settings in the context + self.assertEqual(context['currency'], 'PKR') + self.assertEqual(context['currency_symbol'], 'Rs') def test_clear_cart(self): self.login_user() @@ -841,6 +889,29 @@ class ShoppingCartViewsTests(ModuleStoreTestCase): self.assertIn(reg_item, context['shoppingcart_items'][0]) self.assertIn(cert_item, context['shoppingcart_items'][1]) self.assertFalse(context['any_refunds']) + # check for the default currency settings in the context + self.assertEqual(context['currency_symbol'], '$') + self.assertEqual(context['currency'], 'usd') + + @override_settings(PAID_COURSE_REGISTRATION_CURRENCY=['PKR', 'Rs']) + @patch('shoppingcart.views.render_to_response', render_mock) + def test_show_receipt_success_with_override_currency_settings(self): + reg_item = PaidCourseRegistration.add_to_order(self.cart, self.course_key) + cert_item = CertificateItem.add_to_order(self.cart, self.verified_course_key, self.cost, 'honor') + self.cart.purchase(first='FirstNameTesting123', street1='StreetTesting123') + + self.login_user() + resp = self.client.get(reverse('shoppingcart.views.show_receipt', args=[self.cart.id])) + self.assertEqual(resp.status_code, 200) + + ((template, context), _) = render_mock.call_args # pylint: disable=W0621 + self.assertEqual(template, 'shoppingcart/receipt.html') + self.assertIn(reg_item, context['shoppingcart_items'][0]) + self.assertIn(cert_item, context['shoppingcart_items'][1]) + + # check for the override currency settings in the context + self.assertEqual(context['currency_symbol'], 'Rs') + self.assertEqual(context['currency'], 'PKR') @patch('shoppingcart.views.render_to_response', render_mock) def test_courseregcode_item_total_price(self): diff --git a/lms/djangoapps/shoppingcart/views.py b/lms/djangoapps/shoppingcart/views.py index 806a2d6a97..9326039ca7 100644 --- a/lms/djangoapps/shoppingcart/views.py +++ b/lms/djangoapps/shoppingcart/views.py @@ -156,6 +156,8 @@ def show_cart(request): 'amount': total_cost, 'site_name': site_name, 'form_html': form_html, + 'currency_symbol': settings.PAID_COURSE_REGISTRATION_CURRENCY[1], + 'currency': settings.PAID_COURSE_REGISTRATION_CURRENCY[0], } return render_to_response("shoppingcart/shopping_cart.html", context) @@ -557,6 +559,8 @@ def billing_details(request): 'shoppingcart_items': cart_items, 'amount': total_cost, 'form_html': form_html, + 'currency_symbol': settings.PAID_COURSE_REGISTRATION_CURRENCY[1], + 'currency': settings.PAID_COURSE_REGISTRATION_CURRENCY[0], 'site_name': microsite.get_value('SITE_NAME', settings.SITE_NAME), } return render_to_response("shoppingcart/billing_details.html", context) @@ -636,6 +640,8 @@ def show_receipt(request, ordernum): 'order_type': order_type, 'appended_course_names': appended_course_names, 'appended_recipient_emails': appended_recipient_emails, + 'currency_symbol': settings.PAID_COURSE_REGISTRATION_CURRENCY[1], + 'currency': settings.PAID_COURSE_REGISTRATION_CURRENCY[0], 'total_registration_codes': total_registration_codes, 'registration_codes': registration_codes, 'order_purchase_date': order.purchase_time.strftime("%B %d, %Y"), diff --git a/lms/templates/emails/business_order_confirmation_email.txt b/lms/templates/emails/business_order_confirmation_email.txt index 870ca26c98..40bd104288 100644 --- a/lms/templates/emails/business_order_confirmation_email.txt +++ b/lms/templates/emails/business_order_confirmation_email.txt @@ -27,10 +27,10 @@ ${_("Thank you for your purchase of ")} ${course_names}
${_("Quantity - Description - Price")}
%for order_item in order_items:
- ${order_item.qty} - ${order_item.line_desc} - ${"$" if order_item.currency == 'usd' else ""}${order_item.line_cost}
${_("Total billed to credit/debit card: {currency_symbol}{total_cost}").format(total_cost=order.total_cost, currency_symbol=("$" if order.currency == 'usd' else ""))}
+${_("Total billed to credit/debit card: {currency_symbol}{total_cost}").format(total_cost=order.total_cost, currency_symbol=currency_symbol)}
% if order.company_name: diff --git a/lms/templates/emails/order_confirmation_email.txt b/lms/templates/emails/order_confirmation_email.txt index 87d4c26b80..0648cf0c70 100644 --- a/lms/templates/emails/order_confirmation_email.txt +++ b/lms/templates/emails/order_confirmation_email.txt @@ -22,10 +22,10 @@ ${_("The items in your order are:")} ${_("Quantity - Description - Price")} %for order_item in order_items: - ${order_item.qty} - ${order_item.line_desc} - ${"$" if order_item.currency == 'usd' else ""}${order_item.line_cost} + ${order_item.qty} - ${order_item.line_desc} - ${currency_symbol}${order_item.line_cost} %endfor -${_("Total billed to credit/debit card: {currency_symbol}{total_cost}").format(total_cost=order.total_cost, currency_symbol=("$" if order.currency == 'usd' else ""))} +${_("Total billed to credit/debit card: {currency_symbol}{total_cost}").format(total_cost=order.total_cost, currency_symbol=currency_symbol)} % if has_billing_info: ${order.bill_to_cardtype} ${_("#:")} ${order.bill_to_ccnum} diff --git a/lms/templates/emails/registration_codes_sale_email.txt b/lms/templates/emails/registration_codes_sale_email.txt index 217f8cf763..1c74c9b20e 100644 --- a/lms/templates/emails/registration_codes_sale_email.txt +++ b/lms/templates/emails/registration_codes_sale_email.txt @@ -2,7 +2,7 @@ ${_("Thank you for your purchase of {course_name}!").format(course_name=course.display_name)} -${_("An invoice for ${total_price} is attached. Payment is due immediately. Information on payment methods can be found on the invoice.").format(total_price=sale_price)} +${_("An invoice for {currency_symbol}{total_price} is attached. Payment is due immediately. Information on payment methods can be found on the invoice.").format(currency_symbol=currency_symbol, total_price=sale_price)} ${_("A CSV file of your registration codes is attached. Please distribute registration codes to each student planning to enroll using the email template below.")} diff --git a/lms/templates/emails/registration_codes_sale_invoice_attachment.txt b/lms/templates/emails/registration_codes_sale_invoice_attachment.txt index 53ac470b67..dcb01f2aa5 100644 --- a/lms/templates/emails/registration_codes_sale_invoice_attachment.txt +++ b/lms/templates/emails/registration_codes_sale_invoice_attachment.txt @@ -1,5 +1,4 @@ <%! from django.utils.translation import ugettext as _ %> - ${_("INVOICE")} ——————————————————————————————————————————— @@ -24,13 +23,13 @@ ${invoice.city}, ${invoice.state}, ${invoice.zip} ${invoice.country} ${_("Customer Reference Number: {reference_number}").format(reference_number=invoice.customer_reference_number if invoice.customer_reference_number else "")} - ${_("Balance Due: ${sale_price}").format(sale_price=sale_price)} + ${_("Balance Due: {currency_symbol}{sale_price}").format(currency_symbol=currency_symbol, sale_price=sale_price)} ——————————————————————————————————————————— ${_("Course: {course_name}").format(course_name=course.display_name)} - ${_("Price: ${course_price} Quantity: {quantity} Sub-Total: ${sub_total} Discount: ${discount}").format(course_price=course_price, quantity=quantity, sub_total=sub_total, discount=discount)} -${_("Total: ${sale_price}").format(sale_price=sale_price)} + ${_("Price: {currency_symbol}{course_price} Quantity: {quantity} Sub-Total: {currency_symbol}{sub_total} Discount: {currency_symbol}{discount}").format(course_price=course_price, quantity=quantity, sub_total=sub_total, discount=discount, currency_symbol=currency_symbol)} +${_("Total: {currency_symbol}{sale_price}").format(sale_price=sale_price, currency_symbol=currency_symbol)} ——————————————————————————————————————————— diff --git a/lms/templates/instructor/instructor_dashboard_2/e-commerce.html b/lms/templates/instructor/instructor_dashboard_2/e-commerce.html index 7a2dda941d..3d8f924cfb 100644 --- a/lms/templates/instructor/instructor_dashboard_2/e-commerce.html +++ b/lms/templates/instructor/instructor_dashboard_2/e-commerce.html @@ -44,7 +44,7 @@