mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 05:28:49 -04:00
Remove letters-related code (#175)
This deletes a big ol' chunk of code related to letters. It's not everything—there are still a few things that might be tied to sms/email—but it's the the heart of letters function. SMS and email function should be untouched by this. Areas affected: - Things obviously about letters - PDF tasks, used for precompiling letters - Virus scanning, used for those PDFs - FTP, used to send letters to the printer - Postage stuff
This commit is contained in:
@@ -7,8 +7,6 @@ from app.dao.fact_billing_dao import (
|
||||
fetch_billing_details_for_all_services,
|
||||
fetch_daily_sms_provider_volumes_for_platform,
|
||||
fetch_daily_volumes_for_platform,
|
||||
fetch_letter_costs_and_totals_for_all_services,
|
||||
fetch_letter_line_items_for_all_services,
|
||||
fetch_sms_billing_for_all_services,
|
||||
fetch_volumes_by_service,
|
||||
)
|
||||
@@ -16,7 +14,6 @@ from app.dao.fact_notification_status_dao import (
|
||||
fetch_notification_status_totals_for_all_services,
|
||||
)
|
||||
from app.errors import InvalidRequest, register_errors
|
||||
from app.models import UK_POSTAGE_TYPES
|
||||
from app.platform_stats.platform_stats_schema import platform_stats_request
|
||||
from app.schema_validation import validate
|
||||
from app.service.statistics import format_admin_stats
|
||||
@@ -75,14 +72,7 @@ def get_data_for_billing_report():
|
||||
start_date, end_date = validate_date_range_is_within_a_financial_year(start_date, end_date)
|
||||
|
||||
sms_costs = fetch_sms_billing_for_all_services(start_date, end_date)
|
||||
letter_overview = fetch_letter_costs_and_totals_for_all_services(start_date, end_date)
|
||||
letter_breakdown = fetch_letter_line_items_for_all_services(start_date, end_date)
|
||||
|
||||
lb_by_service = [
|
||||
(lb.service_id,
|
||||
f"{lb.letters_sent} {postage_description(lb.postage)} letters at {format_letter_rate(lb.letter_rate)}")
|
||||
for lb in letter_breakdown
|
||||
]
|
||||
combined = {}
|
||||
for s in sms_costs:
|
||||
if float(s.sms_cost) > 0:
|
||||
@@ -93,34 +83,9 @@ def get_data_for_billing_report():
|
||||
"service_name": s.service_name,
|
||||
"sms_cost": float(s.sms_cost),
|
||||
"sms_chargeable_units": s.chargeable_billable_sms,
|
||||
"total_letters": 0,
|
||||
"letter_cost": 0,
|
||||
"letter_breakdown": ""
|
||||
}
|
||||
combined[s.service_id] = entry
|
||||
|
||||
for data in letter_overview:
|
||||
if data.service_id in combined:
|
||||
combined[data.service_id].update(
|
||||
{'total_letters': data.total_letters, 'letter_cost': float(data.letter_cost)}
|
||||
)
|
||||
|
||||
else:
|
||||
letter_entry = {
|
||||
"organisation_id": str(data.organisation_id) if data.organisation_id else "",
|
||||
"organisation_name": data.organisation_name or "",
|
||||
"service_id": str(data.service_id),
|
||||
"service_name": data.service_name,
|
||||
"sms_cost": 0,
|
||||
"sms_chargeable_units": 0,
|
||||
"total_letters": data.total_letters,
|
||||
"letter_cost": float(data.letter_cost),
|
||||
"letter_breakdown": ""
|
||||
}
|
||||
combined[data.service_id] = letter_entry
|
||||
for service_id, breakdown in lb_by_service:
|
||||
combined[service_id]['letter_breakdown'] += (breakdown + '\n')
|
||||
|
||||
billing_details = fetch_billing_details_for_all_services()
|
||||
for service in billing_details:
|
||||
if service.service_id in combined:
|
||||
@@ -156,8 +121,6 @@ def daily_volumes_report():
|
||||
"sms_fragment_totals": int(row.sms_fragment_totals),
|
||||
"sms_chargeable_units": int(row.sms_chargeable_units),
|
||||
"email_totals": int(row.email_totals),
|
||||
"letter_totals": int(row.letter_totals),
|
||||
"letter_sheet_totals": int(row.letter_sheet_totals)
|
||||
})
|
||||
return jsonify(report)
|
||||
|
||||
@@ -201,23 +164,6 @@ def volumes_by_service_report():
|
||||
"sms_notifications": int(row.sms_notifications),
|
||||
"sms_chargeable_units": int(row.sms_chargeable_units),
|
||||
"email_totals": int(row.email_totals),
|
||||
"letter_totals": int(row.letter_totals),
|
||||
"letter_sheet_totals": int(row.letter_sheet_totals),
|
||||
"letter_cost": float(row.letter_cost),
|
||||
})
|
||||
|
||||
return jsonify(report)
|
||||
|
||||
|
||||
def postage_description(postage):
|
||||
if postage in UK_POSTAGE_TYPES:
|
||||
return f'{postage} class'
|
||||
else:
|
||||
return 'international'
|
||||
|
||||
|
||||
def format_letter_rate(number):
|
||||
if number >= 1:
|
||||
return f"£{number:,.2f}"
|
||||
|
||||
return f"{number * 100:.0f}p"
|
||||
|
||||
Reference in New Issue
Block a user