adding templates and refactor to use dashboard data endpoint

This commit is contained in:
Beverly Nguyen
2025-10-24 14:40:17 -07:00
parent 362c52ce8b
commit 9ead834492
3 changed files with 15 additions and 9 deletions

View File

@@ -77,17 +77,17 @@ def get_organization_message_allowance(org_id):
def get_services_usage(organization, year):
try:
services_and_usage = organization.services_and_usage(financial_year=year, include_all_services=True)["services"]
dashboard_data = organizations_client.get_organization_dashboard(organization.id, year)
services = dashboard_data.get("services", [])
except Exception as e:
current_app.logger.error(f"Error fetching services and usage: {e}")
current_app.logger.error(f"Error fetching dashboard data: {e}")
return []
services = []
for service in services_and_usage:
for service in services:
service["id"] = service.get("service_id")
service["name"] = service.get("service_name")
service["recent_template"] = service.get("recent_sms_template_name")
emails_sent = service.get("emails_sent", 0)
sms_sent = service.get("sms_billable_units", 0)
@@ -105,8 +105,6 @@ def get_services_usage(organization, year):
service["usage"] = ", ".join(usage_parts) if usage_parts else "No usage"
services.append(service)
return services

View File

@@ -83,5 +83,11 @@ class OrganizationsClient(NotifyAdminAPIClient):
url="/organizations/{}/message-allowance".format(org_id),
)
def get_organization_dashboard(self, org_id, year):
return self.get(
url=f"/organizations/{org_id}/dashboard",
params={"year": str(year)},
)
organizations_client = OrganizationsClient()