Billing report only has services with bills to pay

This commit is contained in:
Pea Tyczynska
2021-03-10 17:00:26 +00:00
parent dd278a0567
commit 04525dc8c1
3 changed files with 30 additions and 12 deletions

View File

@@ -77,17 +77,18 @@ def get_data_for_billing_report():
]
combined = {}
for s in sms_costs:
entry = {
"organisation_id": str(s.organisation_id) if s.organisation_id else "",
"organisation_name": s.organisation_name or "",
"service_id": str(s.service_id),
"service_name": s.service_name,
"sms_cost": float(s.sms_cost),
"sms_fragments": s.chargeable_billable_sms,
"letter_cost": 0,
"letter_breakdown": ""
}
combined[s.service_id] = entry
if float(s.sms_cost) > 0:
entry = {
"organisation_id": str(s.organisation_id) if s.organisation_id else "",
"organisation_name": s.organisation_name or "",
"service_id": str(s.service_id),
"service_name": s.service_name,
"sms_cost": float(s.sms_cost),
"sms_fragments": s.chargeable_billable_sms,
"letter_cost": 0,
"letter_breakdown": ""
}
combined[s.service_id] = entry
for letter_cost in letter_costs:
if letter_cost.service_id in combined:

View File

@@ -949,6 +949,7 @@ def set_up_usage_data(start_date):
one_week_later = start_date + timedelta(days=7)
one_month_later = start_date + timedelta(days=31)
# service with sms and letters:
service_1_sms_and_letter = create_service(
service_name='a - with sms and letter',
purchase_order_number="service purchase order number",
@@ -973,6 +974,7 @@ def set_up_usage_data(start_date):
organisation_id=org_1.id
)
# service with emails only:
service_with_emails = create_service(service_name='b - emails')
email_template = create_template(service=service_with_emails, template_type='email')
org_2 = create_organisation(
@@ -980,6 +982,7 @@ def set_up_usage_data(start_date):
)
dao_add_service_to_organisation(service=service_with_emails, organisation_id=org_2.id)
# service with letters:
service_with_letters = create_service(service_name='c - letters only')
letter_template_3 = create_template(service=service_with_letters, template_type='letter')
org_for_service_with_letters = create_organisation(
@@ -991,9 +994,11 @@ def set_up_usage_data(start_date):
)
dao_add_service_to_organisation(service=service_with_letters, organisation_id=org_for_service_with_letters.id)
# service with letters, without an organisation:
service_with_letters_without_org = create_service(service_name='d - service without org')
letter_template_4 = create_template(service=service_with_letters_without_org, template_type='letter')
# service with chargeable SMS, without an organisation
service_with_sms_without_org = create_service(
service_name='b - chargeable sms',
purchase_order_number="sms purchase order number",
@@ -1006,6 +1011,17 @@ def set_up_usage_data(start_date):
service_id=service_with_sms_without_org.id, free_sms_fragment_limit=10, financial_year_start=year
)
# service with SMS within free allowance
service_with_sms_within_allowance = create_service(
service_name='e - sms within allowance'
)
sms_template_2 = create_template(service=service_with_sms_within_allowance, template_type='sms')
create_annual_billing(
service_id=service_with_sms_within_allowance.id, free_sms_fragment_limit=10, financial_year_start=year
)
create_ft_billing(bst_date=one_week_later, template=sms_template_2, billable_unit=2, rate=0.11)
# all other ft billing isntances:
create_ft_billing(bst_date=one_week_earlier, template=sms_template_1, billable_unit=2, rate=0.11)
create_ft_billing(bst_date=start_date, template=sms_template_1, billable_unit=2, rate=0.11)
create_ft_billing(bst_date=two_days_later, template=sms_template_1, billable_unit=1, rate=0.11)

View File

@@ -134,7 +134,8 @@ def test_get_data_for_billing_report(notify_db_session, admin_request):
end_date='2019-06-30'
)
# we set up 5 services, but only 4 returned. service_with_emails was skipped as it had no bills to pay
# we set up 6 services, but only 4 returned. service_with_emails was skipped as it had no bills to pay,
# and likewise the service with SMS within allowance was skipped. too.
assert len(response) == 4
assert response[0]["organisation_id"] == str(setup["org_1"].id)
assert response[0]["service_id"] == str(setup["service_1_sms_and_letter"].id)