Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Add separate setting for formatting unit costs.
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgestar committed Jun 24, 2015
1 parent 9e7f9a1 commit 5f7cfcd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions go/billing/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
DOLLAR_DECIMAL_PLACES = getattr(
settings, 'BILLING_DOLLAR_DECIMAL_PLACES', 3)

UNIT_COST_DOLLAR_DECIMAL_PLACES = getattr(
settings, 'BILLING_UNIT_COST_DOLLAR_DECIMAL_PLACES', 5)

# 10 credits = 1 US cent
CREDIT_CONVERSION_FACTOR = getattr(
settings, 'BILLING_CREDIT_CONVERSION_FACTOR', Decimal('10.00'))
Expand Down
2 changes: 1 addition & 1 deletion go/billing/templates/billing/invoice.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h2>{{ biller.name }}{% if biller.channel_type != None %} ({{ biller.channel_typ
<td>{% if item.description != None %}{{ item.description }}{% endif %}</th>
<td>{{ item.units }}</th>
<td>{% if item.credits != None %}{{ item.credits|format_credits }}{% endif %}</th>
<td>{{ item.unit_cost|format_cents }}</th>
<td>{{ item.unit_cost|format_unit_cost_cents }}</th>
<td>{{ item.cost|format_cents }}
</tr>
{% endfor %}
Expand Down
9 changes: 9 additions & 0 deletions go/billing/templatetags/billing_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ def format_cents(v):
return format_currency(v, places=settings.DOLLAR_DECIMAL_PLACES)


@register.filter
def format_unit_cost_cents(v):
"""A version of ``format_cents`` tailored to format small fractions of cents
for displaying unit costs.
"""
v = v / Decimal('100.0')
return format_currency(v, places=settings.UNIT_COST_DOLLAR_DECIMAL_PLACES)


@register.filter
def format_credits(v):
"""Returns a formatted string representation of a number in credits from a
Expand Down
4 changes: 2 additions & 2 deletions go/billing/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ def test_statement_description_nones(self):
def test_statement_costs(self):
statement = self.mk_statement(items=[{
'credits': Decimal('200.0'),
'unit_cost': Decimal('123.456'),
'unit_cost': Decimal('123.45678'),
'cost': Decimal('679.012'),
}])

user = self.user_helper.get_django_user()
response = self.get_statement(user, statement)

self.assertContains(response, '>200.00<')
self.assertContains(response, '>1.234<')
self.assertContains(response, '>1.23456<')
self.assertContains(response, '>6.790<')

def test_statement_cost_nones(self):
Expand Down

0 comments on commit 5f7cfcd

Please sign in to comment.