Repository: fossasia/open-event-server

Issue:
Number formats and currencies do not adhere to language setting
Currencies and formats in different languages are defined differently, e.g. 2 Euro in French are 2,00 Euro, but in English it is 2.00 Euro. Please implement this in the invoices, emails and UI of the system for all languages.


Discussion:
Can someone assign me?

We don't assign issues to external contributors. Please comment that you're working on the issue after checking that no one else is, and then send a pull request for it. Thank You!
I am working on this issue.

Resolving patch:
diff --git a/app/api/helpers/mail.py b/app/api/helpers/mail.py
--- a/app/api/helpers/mail.py
+++ b/app/api/helpers/mail.py
@@ -26,6 +26,7 @@
     format_time,
     format_datetime
 )
+from babel.numbers import format_currency
 
 logger = logging.getLogger(__name__)
 # pytype: disable=attribute-error
@@ -658,8 +659,11 @@ def send_order_purchase_organizer_email(order, recipients):
         ),
         payment_mode=order.payment_mode,
         payment_status=order.status,
-        order_amount=order.amount,
-        payment_currency=order.event.payment_currency,
+        order_amount=convert_to_user_locale(
+            emails[0],
+            amount=order.amount,
+            currency=order.event.payment_currency
+        ),
         tickets_count=order.tickets_count,
         order_tickets=order_tickets,
         buyer_org=order.company,
@@ -823,9 +827,9 @@ def send_email_after_event_speaker(email, event_name):
     )
 
 
-def convert_to_user_locale(email, date_time=None, date=None, time=None, tz=None):
+def convert_to_user_locale(email, date_time=None, date=None, time=None, tz=None, amount=None, currency=None):
     """
-    Convert date and time to user selected language
+    Convert date and time and amount to user selected language
     :return        : datetime/date/time translated to user locale
     """
     if email:
@@ -835,6 +839,9 @@ def convert_to_user_locale(email, date_time=None, date=None, time=None, tz=None)
         if user and user.language_prefrence:
             user_locale = user.language_prefrence
 
+        if amount and currency:
+            return format_currency(amount, currency, locale=user_locale)
+
         if date_time and tz:
             return format_datetime(
                 date_time,
diff --git a/app/api/helpers/order.py b/app/api/helpers/order.py
--- a/app/api/helpers/order.py
+++ b/app/api/helpers/order.py
@@ -78,19 +78,22 @@ def create_pdf_tickets_for_holder(order):
     :param order: The order for which to create tickets for.
     """
     starts_at = convert_to_user_locale(
-        order.user.email,
-        date_time=order.event.starts_at,
-        tz=order.event.timezone
+        order.user.email, date_time=order.event.starts_at, tz=order.event.timezone
     )
     ends_at = convert_to_user_locale(
-        order.user.email,
-        date_time=order.event.ends_at,
-        tz=order.event.timezone
+        order.user.email, date_time=order.event.ends_at, tz=order.event.timezone
     )
     admin_info = Setting.query.first()
     if order.status == 'completed' or order.status == 'placed':
         pdf = create_save_pdf(
-            render_template('pdf/ticket_purchaser.html', order=order,app_name=get_settings()['app_name'],admin_info=admin_info,starts_at=starts_at,ends_at=ends_at),
+            render_template(
+                'pdf/ticket_purchaser.html',
+                order=order,
+                app_name=get_settings()['app_name'],
+                admin_info=admin_info,
+                starts_at=starts_at,
+                ends_at=ends_at,
+            ),
             UPLOAD_PATHS['pdf']['tickets_all'],
             dir_path='/static/uploads/pdf/tickets/',
             identifier=order.identifier,
@@ -102,19 +105,23 @@ def create_pdf_tickets_for_holder(order):
 
         for holder in order.ticket_holders:
             starts_at = convert_to_user_locale(
-                holder.email,
-                date_time=order.event.starts_at,
-                tz=order.event.timezone
+                holder.email, date_time=order.event.starts_at, tz=order.event.timezone
             )
             ends_at = convert_to_user_locale(
-                holder.email,
-                date_time=order.event.ends_at,
-                tz=order.event.timezone
+                holder.email, date_time=order.event.ends_at, tz=order.event.timezone
             )
 
             # create attendee pdf for every ticket holder
             pdf = create_save_pdf(
-                render_template('pdf/ticket_attendee.html', order=order, holder=holder,app_name=get_settings()['app_name'],admin_info=admin_info,starts_at=starts_at,ends_at=ends_at),
+                render_template(
+                    'pdf/ticket_attendee.html',
+                    order=order,
+                    holder=holder,
+                    app_name=get_settings()['app_name'],
+                    admin_info=admin_info,
+                    starts_at=starts_at,
+                    ends_at=ends_at,
+                ),
                 UPLOAD_PATHS['pdf']['tickets_all'],
                 dir_path='/static/uploads/pdf/tickets/',
                 identifier=order.identifier,
@@ -123,7 +130,6 @@ def create_pdf_tickets_for_holder(order):
             )
             holder.pdf_url = pdf
             save_to_db(holder)
-        
 
         # create order invoices pdf
         order_tickets = OrderTicket.query.filter_by(order_id=order.id).all()
@@ -133,12 +139,12 @@ def create_pdf_tickets_for_holder(order):
             ticket = dict(
                 id=order_ticket.ticket.id,
                 price=order_ticket.price,
-                quantity=order_ticket.quantity
+                quantity=order_ticket.quantity,
             )
             tickets.append(ticket)
-        
+
         # calculate order amount using helper function
-        order_amount = calculate_order_amount(tickets, discount_code=order.discount_code)            
+        order_amount = calculate_order_amount(tickets, discount_code=order.discount_code)
 
         create_save_pdf(
             render_template(
@@ -298,9 +304,13 @@ def calculate_order_amount(tickets, discount_code=None):
                         discount_percent = (discount_amount / price) * 100
                         if tax:
                             if tax_included:
-                                discounted_tax = (price - discount_amount) - (price - discount_amount) / (1 + tax.rate / 100)
+                                discounted_tax = (price - discount_amount) - (
+                                    price - discount_amount
+                                ) / (1 + tax.rate / 100)
                             else:
-                                discounted_tax = (price - discount_amount) * tax.rate / 100
+                                discounted_tax = (
+                                    (price - discount_amount) * tax.rate / 100
+                                )
                     else:
                         discount_amount = (price * code.value) / 100
                         if tax:
@@ -311,7 +321,7 @@ def calculate_order_amount(tickets, discount_code=None):
                         'percent': round(discount_percent, 2),
                         'amount': round(discount_amount, 2),
                         'total': round(discount_amount * quantity, 2),
-                        'type': code.type
+                        'type': code.type,
                     }
 
         total_discount += round(discount_amount * quantity, 2)
@@ -331,7 +341,7 @@ def calculate_order_amount(tickets, discount_code=None):
                 'ticket_fee': round(ticket_fee, 2),
                 'sub_total': round(sub_total, 2),
                 'ticket_tax': round(ticket_tax, 2),
-                'discounted_tax': round(discounted_tax, 2)
+                'discounted_tax': round(discounted_tax, 2),
             }
         )
 
diff --git a/app/templates/flask_ext/jinja/filters.py b/app/templates/flask_ext/jinja/filters.py
--- a/app/templates/flask_ext/jinja/filters.py
+++ b/app/templates/flask_ext/jinja/filters.py
@@ -5,6 +5,7 @@
 from forex_python.converter import CurrencyCodes
 
 from app.api.helpers.utilities import strip_tags
+from app.api.helpers.mail import convert_to_user_locale
 
 
 def humanize_helper(time):
@@ -22,8 +23,8 @@ def currency_symbol_filter(currency_code):
         return symbol if symbol else currency_code
 
     @app.template_filter('money')
-    def money_filter(string):
-        return '{:20,.2f}'.format(float(string))
+    def money_filter(amount, email, currency):
+        return convert_to_user_locale(email, amount=amount, currency=currency)
 
     @app.template_filter('datetime')
     def simple_datetime_display(date, timezone=None, format='%B %d, %Y %H:%M (%Z%z)'):


Test patch: