mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-29 10:30:20 -04:00
Merge pull request #4221 from alphagov/usage-tidyup
Show monthly usage rate correctly if the sms rate has changed during the financial year
This commit is contained in:
@@ -406,7 +406,6 @@ def get_sum_billing_units(billing_units, month=None):
|
||||
|
||||
def get_free_paid_breakdown_for_billable_units(year, free_sms_fragment_limit, billing_units):
|
||||
cumulative = 0
|
||||
letter_cumulative = 0
|
||||
sms_units = [x for x in billing_units if x['notification_type'] == 'sms']
|
||||
letter_units = [x for x in billing_units if x['notification_type'] == 'letter']
|
||||
for month in get_months_for_financial_year(year):
|
||||
@@ -424,14 +423,13 @@ def get_free_paid_breakdown_for_billable_units(year, free_sms_fragment_limit, bi
|
||||
letter_total = 0
|
||||
for x in letter_billing:
|
||||
letter_total += x.cost
|
||||
letter_cumulative += letter_total
|
||||
yield {
|
||||
'name': month,
|
||||
'letter_total': letter_total,
|
||||
'letter_cumulative': letter_cumulative,
|
||||
'paid': breakdown['paid'],
|
||||
'free': breakdown['free'],
|
||||
'letters': letter_billing
|
||||
'letters': letter_billing,
|
||||
'sms_paid_count': breakdown['paid'],
|
||||
'sms_free_count': breakdown['free'],
|
||||
'sms_rate': breakdown['sms_rate'],
|
||||
}
|
||||
|
||||
|
||||
@@ -479,23 +477,31 @@ def get_free_paid_breakdown_for_month(
|
||||
):
|
||||
allowance = free_sms_fragment_limit
|
||||
|
||||
# makes the assumption that there is either no item in `monthly_usage` because they have not sent any SMS
|
||||
# or that they have sent SMS and that there is only a single item in `monthly_usage` because they have only
|
||||
# been sent at a single rate during the month
|
||||
sms_rate = monthly_usage[0]['rate'] if len(monthly_usage) else 0
|
||||
|
||||
total_monthly_billing_units = get_sum_billing_units(monthly_usage)
|
||||
|
||||
if cumulative < allowance:
|
||||
return {
|
||||
'paid': 0,
|
||||
'free': total_monthly_billing_units,
|
||||
'sms_rate': sms_rate,
|
||||
}
|
||||
elif previous_cumulative < allowance:
|
||||
remaining_allowance = allowance - previous_cumulative
|
||||
return {
|
||||
'paid': total_monthly_billing_units - remaining_allowance,
|
||||
'free': remaining_allowance,
|
||||
'sms_rate': sms_rate,
|
||||
}
|
||||
else:
|
||||
return {
|
||||
'paid': total_monthly_billing_units,
|
||||
'free': 0,
|
||||
'sms_rate': sms_rate,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -97,17 +97,17 @@
|
||||
{% endcall %}
|
||||
{% call field(align='left') %}
|
||||
{{ big_number(
|
||||
(sms_rate * month.paid) + month.letter_total,
|
||||
(month.sms_rate * month.sms_paid_count) + month.letter_total,
|
||||
currency="£",
|
||||
smallest=True
|
||||
) }}
|
||||
<ul>
|
||||
{% if month.free %}
|
||||
<li class="tabular-numbers">{{ month.free|format_thousands }} free {{ month.free|message_count_label('sms', suffix='') }}</li>
|
||||
{% if month.sms_free_count %}
|
||||
<li class="tabular-numbers">{{ month.sms_free_count|format_thousands }} free {{ month.sms_free_count|message_count_label('sms', suffix='') }}</li>
|
||||
{% endif %}
|
||||
{% if month.paid %}
|
||||
<li class="tabular-numbers">{{ month.paid|message_count('sms') }} at
|
||||
{{- ' {:.2f}p'.format(sms_rate * 100) }}</li>
|
||||
{% if month.sms_paid_count %}
|
||||
<li class="tabular-numbers">{{ month.sms_paid_count|message_count('sms') }} at
|
||||
{{- ' {:.2f}p'.format(month.sms_rate * 100) }}</li>
|
||||
{% endif %}
|
||||
{% for letter in month.letters%}
|
||||
{% if letter.billing_units %}
|
||||
@@ -115,7 +115,7 @@
|
||||
{{ letter.rate | format_number_in_pounds_as_currency }}</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if not (month.free or month.paid or month.letters) %}
|
||||
{% if not (month.sms_free_count or month.sms_paid_count or month.letters) %}
|
||||
<li aria-hidden="true">–</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user