Add letters to usage page.

Before this goes live need to only show letters on usage if the service has the permission.
This commit is contained in:
Rebecca Law
2017-12-19 14:35:10 +00:00
parent 084be530a6
commit b7db7debc5
4 changed files with 61 additions and 25 deletions

View File

@@ -337,6 +337,11 @@ def calculate_usage(usage, free_sms_fragment_limit):
emails = [breakdown["billing_units"] for breakdown in usage if breakdown['notification_type'] == 'email']
emails_sent = 0 if len(emails) == 0 else emails[0]
letters = [(breakdown["billing_units"], breakdown['letter_total']) for breakdown in usage if
breakdown['notification_type'] == 'letter']
letter_sent = 0 if len(letters) == 0 else letters[0][0]
letter_cost = 0 if len(letters) == 0 else letters[0][1]
return {
'emails_sent': emails_sent,
'sms_free_allowance': sms_free_allowance,
@@ -344,6 +349,8 @@ def calculate_usage(usage, free_sms_fragment_limit):
'sms_allowance_remaining': max(0, (sms_free_allowance - sms_sent)),
'sms_chargeable': max(0, sms_sent - sms_free_allowance),
'sms_rate': sms_rate,
'letter_sent': letter_sent,
'letter_cost': letter_cost
}
@@ -409,10 +416,16 @@ def get_free_paid_breakdown_for_billable_units(year, free_sms_fragment_limit, bi
free_sms_fragment_limit, cumulative, previous_cumulative,
[billing_month for billing_month in sms_units if billing_month['month'] == month]
)
letter_billing = [(x['billing_units'], x['rate']) for x in letter_units if x['month'] == month]
letter_billing = [(x['billing_units'], x['rate'], (x['billing_units'] * x['rate']))
for x in letter_units if x['month'] == month]
letter_total = 0
for x in letter_billing:
letter_total += x[2]
letter_cumulative += letter_total
yield {
'name': month,
# 'total': sms + letter
'letter_total': letter_total,
'letter_cumulative': letter_cumulative,
'paid': breakdown['paid'],
'free': breakdown['free'],
'letters': letter_billing

View File

@@ -17,14 +17,14 @@
</div>
<div id='pill-selected-item'>
<div class='grid-row'>
<div class='column-half'>
<div class='column-one-third'>
<h2 class='heading-small'>Emails</h2>
<div class="keyline-block">
{{ big_number(emails_sent, 'sent', smaller=True) }}
{{ big_number("Unlimited", 'free allowance', smaller=True) }}
</div>
</div>
<div class='column-half'>
<div class='column-one-third'>
<h2 class='heading-small'>Text messages</h2>
<div class="keyline-block">
{{ big_number(sms_sent, 'sent', smaller=True) }}
@@ -39,15 +39,21 @@
{% endif %}
</div>
</div>
<div class='column-one-third'>
<h2 class='heading-small'>Letters</h2>
<div class="keyline-block">
{{ big_number(letter_sent, 'sent', smaller=True) }}
</div>
</div>
</div>
<div class='grid-row'>
<div class='column-half'>
<div class='column-one-third'>
<div class="keyline-block">
&nbsp;
</div>
</div>
<div class='column-half'>
<div class='column-one-third'>
<div class="keyline-block">
{{ big_number(
(sms_chargeable * sms_rate),
@@ -57,6 +63,17 @@
) }}
</div>
</div>
<div class='column-one-third'>
<div class="keyline-block">
{{ big_number(
letter_cost,
'spent',
currency="£",
smaller=True
) }}
</div>
</div>
</div>
{% if months %}
@@ -77,7 +94,7 @@
{% endcall %}
{% call field(align='left') %}
{{ big_number(
sms_rate * month.paid,
(sms_rate * month.paid) + month.letter_total,
currency="£",
smallest=True
) }}
@@ -94,10 +111,9 @@
{% endif %}
</ul>
<ul>
{{ month.letters }}
{% for letter in month.letters%}
{% if letter[0] %}
<li class="tabular-numbers">{{ letter[0]}} letters at {{ ' {:.0f}p'.format(letter[1] * 100) }}
<li class="tabular-numbers">{{ "{:,}".format(letter[0])}} letters at {{ '{:.0f}p'.format(letter[1] * 100) }}
</li>
{% endif %}
{% endfor %}