mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 00:06:16 -04:00
Billing report only has services with bills to pay
This commit is contained in:
@@ -77,17 +77,18 @@ def get_data_for_billing_report():
|
|||||||
]
|
]
|
||||||
combined = {}
|
combined = {}
|
||||||
for s in sms_costs:
|
for s in sms_costs:
|
||||||
entry = {
|
if float(s.sms_cost) > 0:
|
||||||
"organisation_id": str(s.organisation_id) if s.organisation_id else "",
|
entry = {
|
||||||
"organisation_name": s.organisation_name or "",
|
"organisation_id": str(s.organisation_id) if s.organisation_id else "",
|
||||||
"service_id": str(s.service_id),
|
"organisation_name": s.organisation_name or "",
|
||||||
"service_name": s.service_name,
|
"service_id": str(s.service_id),
|
||||||
"sms_cost": float(s.sms_cost),
|
"service_name": s.service_name,
|
||||||
"sms_fragments": s.chargeable_billable_sms,
|
"sms_cost": float(s.sms_cost),
|
||||||
"letter_cost": 0,
|
"sms_fragments": s.chargeable_billable_sms,
|
||||||
"letter_breakdown": ""
|
"letter_cost": 0,
|
||||||
}
|
"letter_breakdown": ""
|
||||||
combined[s.service_id] = entry
|
}
|
||||||
|
combined[s.service_id] = entry
|
||||||
|
|
||||||
for letter_cost in letter_costs:
|
for letter_cost in letter_costs:
|
||||||
if letter_cost.service_id in combined:
|
if letter_cost.service_id in combined:
|
||||||
|
|||||||
@@ -949,6 +949,7 @@ def set_up_usage_data(start_date):
|
|||||||
one_week_later = start_date + timedelta(days=7)
|
one_week_later = start_date + timedelta(days=7)
|
||||||
one_month_later = start_date + timedelta(days=31)
|
one_month_later = start_date + timedelta(days=31)
|
||||||
|
|
||||||
|
# service with sms and letters:
|
||||||
service_1_sms_and_letter = create_service(
|
service_1_sms_and_letter = create_service(
|
||||||
service_name='a - with sms and letter',
|
service_name='a - with sms and letter',
|
||||||
purchase_order_number="service purchase order number",
|
purchase_order_number="service purchase order number",
|
||||||
@@ -973,6 +974,7 @@ def set_up_usage_data(start_date):
|
|||||||
organisation_id=org_1.id
|
organisation_id=org_1.id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# service with emails only:
|
||||||
service_with_emails = create_service(service_name='b - emails')
|
service_with_emails = create_service(service_name='b - emails')
|
||||||
email_template = create_template(service=service_with_emails, template_type='email')
|
email_template = create_template(service=service_with_emails, template_type='email')
|
||||||
org_2 = create_organisation(
|
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)
|
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')
|
service_with_letters = create_service(service_name='c - letters only')
|
||||||
letter_template_3 = create_template(service=service_with_letters, template_type='letter')
|
letter_template_3 = create_template(service=service_with_letters, template_type='letter')
|
||||||
org_for_service_with_letters = create_organisation(
|
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)
|
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')
|
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')
|
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_with_sms_without_org = create_service(
|
||||||
service_name='b - chargeable sms',
|
service_name='b - chargeable sms',
|
||||||
purchase_order_number="sms purchase order number",
|
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_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=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=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)
|
create_ft_billing(bst_date=two_days_later, template=sms_template_1, billable_unit=1, rate=0.11)
|
||||||
|
|||||||
@@ -134,7 +134,8 @@ def test_get_data_for_billing_report(notify_db_session, admin_request):
|
|||||||
end_date='2019-06-30'
|
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 len(response) == 4
|
||||||
assert response[0]["organisation_id"] == str(setup["org_1"].id)
|
assert response[0]["organisation_id"] == str(setup["org_1"].id)
|
||||||
assert response[0]["service_id"] == str(setup["service_1_sms_and_letter"].id)
|
assert response[0]["service_id"] == str(setup["service_1_sms_and_letter"].id)
|
||||||
|
|||||||
Reference in New Issue
Block a user