Create filter for dollar amounts

This commit is contained in:
leigh-mil 2019-01-18 11:01:24 -05:00
parent a4d920d005
commit 635c301db4
2 changed files with 14 additions and 5 deletions

View File

@ -19,6 +19,14 @@ def dollars(value):
return "${:,.0f}".format(numberValue) return "${:,.0f}".format(numberValue)
def dollarsWithCents(value):
try:
numberValue = float(value)
except ValueError:
numberValue = 0
return "${:,.2f}".format(numberValue)
def usPhone(number): def usPhone(number):
phone = re.sub(r"\D", "", number) phone = re.sub(r"\D", "", number)
return "+1 ({}) {} - {}".format(phone[0:3], phone[3:6], phone[6:]) return "+1 ({}) {} - {}".format(phone[0:3], phone[3:6], phone[6:])
@ -113,6 +121,7 @@ def normalizeOrder(title):
def register_filters(app): def register_filters(app):
app.jinja_env.filters["iconSvg"] = iconSvg app.jinja_env.filters["iconSvg"] = iconSvg
app.jinja_env.filters["dollars"] = dollars app.jinja_env.filters["dollars"] = dollars
app.jinja_env.filters["dollarsWithCents"] = dollarsWithCents
app.jinja_env.filters["usPhone"] = usPhone app.jinja_env.filters["usPhone"] = usPhone
app.jinja_env.filters["readableInteger"] = readableInteger app.jinja_env.filters["readableInteger"] = readableInteger
app.jinja_env.filters["getOptionLabel"] = getOptionLabel app.jinja_env.filters["getOptionLabel"] = getOptionLabel

View File

@ -39,23 +39,23 @@
{% endif %} {% endif %}
{% if task_order.budget %} {% if task_order.budget %}
{% set budget = '${:,.2f}'.format(task_order.budget) %} {% set budget = task_order.budget | dollarsWithCents %}
{% endif %} {% endif %}
{% if task_order.clin_01 %} {% if task_order.clin_01 %}
{% set clin_01 = '${:,.2f}'.format(task_order.clin_01) %} {% set clin_01 = task_order.clin_01 | dollarsWithCents %}
{% endif %} {% endif %}
{% if task_order.clin_02 %} {% if task_order.clin_02 %}
{% set clin_02 = '${:,.2f}'.format(task_order.clin_02) %} {% set clin_02 = task_order.clin_02 | dollarsWithCents %}
{% endif %} {% endif %}
{% if task_order.clin_03 %} {% if task_order.clin_03 %}
{% set clin_03 = '${:,.2f}'.format(task_order.clin_03) %} {% set clin_03 = task_order.clin_03 | dollarsWithCents %}
{% endif %} {% endif %}
{% if task_order.clin_04 %} {% if task_order.clin_04 %}
{% set clin_04 = '${:,.2f}'.format(task_order.clin_04) %} {% set clin_04 = task_order.clin_04 | dollarsWithCents %}
{% endif %} {% endif %}
{% if task_order.ko_phone_number %} {% if task_order.ko_phone_number %}