Commit 2fd7a83e by chrisndodge

Merge pull request #6068 from edx/muhhshoaib/WL-163

The USD symbol $ is hard coded into the HTML templates
parents 17aa898a 9fddc694
......@@ -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 <a href="http://example.com/courses/{}" ' \
'target="_blank">Example</a>.'.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):
......
......@@ -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,
......
......@@ -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()}),
......
......@@ -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),
......
......@@ -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):
......
......@@ -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"),
......
......@@ -27,10 +27,10 @@ ${_("Thank you for your purchase of ")} <b> ${course_names} </b>
<p>${_("Quantity - Description - Price")}<br>
%for order_item in order_items:
${order_item.qty} - ${order_item.line_desc} - ${"$" if order_item.currency == 'usd' else ""}${order_item.line_cost}</p>
${order_item.qty} - ${order_item.line_desc} - ${currency_symbol}${order_item.line_cost}</p>
%endfor
<p>${_("Total billed to credit/debit card: {currency_symbol}{total_cost}").format(total_cost=order.total_cost, currency_symbol=("$" if order.currency == 'usd' else ""))}</p>
<p>${_("Total billed to credit/debit card: {currency_symbol}{total_cost}").format(total_cost=order.total_cost, currency_symbol=currency_symbol)}</p>
<p>
% if order.company_name:
......
......@@ -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}
......
......@@ -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.")}
......
<%! 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)}
———————————————————————————————————————————
......
......@@ -44,7 +44,7 @@
<div class="wrap">
<h2>${_("Course Price")}</h2>
<div>
<span class="tip">${_("Course Price: ")}<span>$${section_data['course_price']}</span>
<span class="tip">${_("Course Price: ")}<span>${section_data['currency_symbol']}${section_data['course_price']}</span>
%if section_data['access']['finance_admin'] is True:
<a id="course_price_link" href="#set-course-mode-price-modal" rel="leanModal" class="add blue-button">+ ${_('Set Price')}</a>
%endif
......@@ -57,7 +57,7 @@
<h2>${_("Transactions")}</h2>
<div>
%if section_data['total_amount'] is not None:
<span>${_("Total Amount: ")}<span>$${section_data['total_amount']}</span></span>
<span>${_("Total Amount: ")}<span>${section_data['currency_symbol']}${section_data['total_amount']}</span></span>
%endif
<span class="csv_tip">${_("Click to generate a CSV file for all purchase transactions in this course")}
......
......@@ -36,7 +36,7 @@
</div>
<div class="discount">
<div class="code-text">
<span class="pull-right">${_('Total')}: <b>$${"{0:0.2f}".format(amount)} USD</b></span>
<span class="pull-right">${_('Total')}: <b>${currency_symbol}${"{0:0.2f}".format(amount)} ${currency.upper()}</b></span>
</div>
</div>
<div class="col-two">
......
......@@ -299,11 +299,11 @@ from courseware.courses import course_image_url, get_course_about_section, get_c
% if item.status == "purchased":
<div class="col-1">
% if item.list_price != None:
<div class="price">${_('Price per student:')} <span class="line-through"> $${"{0:0.2f}".format(item.list_price)}</span>
<div class="price">${_('Price per student:')} <span class="line-through"> ${currency_symbol}${"{0:0.2f}".format(item.list_price)}</span>
</div>
<div class="price green">${_('Discount Applied:')} <span> $${"{0:0.2f}".format(item.unit_cost)} </span></div>
<div class="price green">${_('Discount Applied:')} <span> ${currency_symbol}${"{0:0.2f}".format(item.unit_cost)} </span></div>
% else:
<div class="price">${_('Price per student:')} <span> $${"{0:0.2f}".format(item.unit_cost)}</span></div>
<div class="price">${_('Price per student:')} <span> ${currency_symbol}${"{0:0.2f}".format(item.unit_cost)}</span></div>
% endif
</div>
<div class="col-2">
......@@ -317,12 +317,12 @@ from courseware.courses import course_image_url, get_course_about_section, get_c
% elif item.status == "refunded":
<div class="col-1">
% if item.list_price != None:
<div class="price">${_('Price per student:')} <span class="line-through"> $${"{0:0.2f}".format(item.list_price)}</span>
<div class="price">${_('Price per student:')} <span class="line-through"> ${currency_symbol}${"{0:0.2f}".format(item.list_price)}</span>
</div>
<div class="price green">${_('Discount Applied:')} <span><del> $${"{0:0.2f}".format(item.unit_cost)}
<div class="price green">${_('Discount Applied:')} <span><del> ${currency_symbol}${"{0:0.2f}".format(item.unit_cost)}
</del></span></div>
% else:
<div class="price">${_('Price per student:')} <span><del> $${"{0:0.2f}".format(item.unit_cost)}</del></span>
<div class="price">${_('Price per student:')} <span><del> ${currency_symbol}${"{0:0.2f}".format(item.unit_cost)}</del></span>
</div>
% endif
</div>
......@@ -348,7 +348,7 @@ from courseware.courses import course_image_url, get_course_about_section, get_c
${_("Note: items with strikethough like <del>this</del> have been refunded.")}
</span>
% endif
<span class="pull-right">${_("Total")}: <b>$${"{0:0.2f}".format(order.total_cost)} USD</b></span>
<span class="pull-right">${_("Total")}: <b> ${currency_symbol}${"{0:0.2f}".format(order.total_cost)} ${currency.upper()}</b></span>
</div>
</div>
## Allow for a microsite to be able to insert additional text at the bottom of the page
......
......@@ -40,10 +40,10 @@ from django.utils.translation import ugettext as _
<div class="col-1">
% if item.list_price != None:
<% discount_applied = True %>
<div class="price">${_('Price per student:')} <span class="line-through"> $${"{0:0.2f}".format(item.list_price)}</span></div>
<div class="price green">${_('Discount Applied:')} <span> $${"{0:0.2f}".format(item.unit_cost)} </span></div>
<div class="price">${_('Price per student:')} <span class="line-through"> ${currency_symbol}${"{0:0.2f}".format(item.list_price)}</span></div>
<div class="price green">${_('Discount Applied:')} <span> ${currency_symbol}${"{0:0.2f}".format(item.unit_cost)} </span></div>
% else:
<div class="price">${_('Price per student:')} <span> $${"{0:0.2f}".format(item.unit_cost)}</span></div>
<div class="price">${_('Price per student:')} <span> ${currency_symbol}${"{0:0.2f}".format(item.unit_cost)}</span></div>
% endif
</div>
<div class="col-2">
......@@ -82,7 +82,7 @@ from django.utils.translation import ugettext as _
<input type="submit" value="Reset" class="blue-border" id="submit-reset-redemption">
</div>
%endif
<span class="pull-right">${_('Total:')} <b id="total-amount">$${"{0:0.2f}".format(amount)} USD</b></span>
<span class="pull-right">${_('Total:')} <b id="total-amount">${currency_symbol}${"{0:0.2f}".format(amount)} ${currency.upper()}</b></span>
</div>
</div>
<div class="col-two">
......
Markdown is supported
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