From 11d7f5839db1065ebaddbb4cd0f04be502e774dc Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Tue, 14 Oct 2025 15:28:58 -0700 Subject: [PATCH] Add Service Status and message usage count --- app/main/views/organizations.py | 32 ++++++++++++++++++- .../organizations/organization/index.html | 16 ++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/app/main/views/organizations.py b/app/main/views/organizations.py index c6d50b5f2..7c3bbde33 100644 --- a/app/main/views/organizations.py +++ b/app/main/views/organizations.py @@ -1,4 +1,4 @@ -from collections import OrderedDict +from collections import Counter, OrderedDict from datetime import datetime from functools import partial @@ -34,6 +34,28 @@ from app.utils.user import user_has_permissions, user_is_platform_admin from notifications_python_client.errors import HTTPError +def get_service_counts_by_status(services): + """ + Calculate service counts by status. + """ + def get_status(service): + if not service.get("active"): + return "suspended" + elif service.get("restricted"): + return "trial" + else: + return "live" + + status_counts = Counter(get_status(service) for service in services) + + return { + "live": status_counts["live"], + "trial": status_counts["trial"], + "suspended": status_counts["suspended"], + "total": len(services), + } + + @main.route("/organizations", methods=["GET"]) @user_is_platform_admin def organizations(): @@ -77,6 +99,9 @@ def organization_dashboard(org_id): services = current_organization.services_and_usage(financial_year=year)["services"] + all_services = current_organization.services + service_counts = get_service_counts_by_status(all_services) + total_messages_sent = 0 total_messages_remaining = 0 @@ -92,6 +117,11 @@ def organization_dashboard(org_id): selected_year=year, messages_sent=total_messages_sent, messages_remaining=total_messages_remaining, + total_services=service_counts["total"], + live_services=service_counts["live"], + trial_services=service_counts["trial"], + suspended_services=service_counts["suspended"], + all_services=all_services ) diff --git a/app/templates/views/organizations/organization/index.html b/app/templates/views/organizations/organization/index.html index baabccb73..33051839e 100644 --- a/app/templates/views/organizations/organization/index.html +++ b/app/templates/views/organizations/organization/index.html @@ -26,6 +26,22 @@
+
+
+
+
+
+

+ Services: {{ total_services }} (Live: {{ live_services }} - Trial: {{ trial_services }} - Suspended: {{ suspended_services }}) +

+

+ Agreement: Jan 1 - Dec 31 +

+
+
+
+
+

What is a service?