From e97fdbf140dc22ee8c90fcd9e1f7383f74c43161 Mon Sep 17 00:00:00 2001 From: dandds Date: Tue, 14 Aug 2018 16:57:27 -0400 Subject: [PATCH] implement real KPI counts --- atst/domain/requests.py | 18 ++++++++++++++- atst/models/request_status_event.py | 1 + atst/routes/requests/index.py | 36 +++++++++++++++++++++-------- templates/requests.html | 12 +++++----- tests/domain/test_requests.py | 7 +++--- 5 files changed, 55 insertions(+), 19 deletions(-) diff --git a/atst/domain/requests.py b/atst/domain/requests.py index 3d50d887..f36551d3 100644 --- a/atst/domain/requests.py +++ b/atst/domain/requests.py @@ -158,7 +158,7 @@ class Requests(object): return request.status == RequestStatus.PENDING_CCPO_APPROVAL @classmethod - def count_status(self, status): + def status_count(cls, status): raw = text(""" SELECT count(requests_with_status.id) FROM ( @@ -174,3 +174,19 @@ WHERE requests_with_status.status = :status; (count,) = results return count + @classmethod + def in_progress_count(cls): + return sum([ + Requests.status_count(RequestStatus.STARTED), + Requests.status_count(RequestStatus.PENDING_FINANCIAL_VERIFICATION), + Requests.status_count(RequestStatus.CHANGES_REQUESTED), + ]) + + @classmethod + def pending_ccpo_count(cls): + return Requests.status_count(RequestStatus.PENDING_CCPO_APPROVAL) + + @classmethod + def completed_count(cls): + return Requests.status_count(RequestStatus.APPROVED) + diff --git a/atst/models/request_status_event.py b/atst/models/request_status_event.py index 81505f2a..cb092403 100644 --- a/atst/models/request_status_event.py +++ b/atst/models/request_status_event.py @@ -12,6 +12,7 @@ class RequestStatus(Enum): STARTED = "Started" PENDING_FINANCIAL_VERIFICATION = "Pending Financial Verification" PENDING_CCPO_APPROVAL = "Pending CCPO Approval" + CHANGES_REQUESTED = "Changes Requested" APPROVED = "Approved" EXPIRED = "Expired" DELETED = "Deleted" diff --git a/atst/routes/requests/index.py b/atst/routes/requests/index.py index 7130c722..69da2058 100644 --- a/atst/routes/requests/index.py +++ b/atst/routes/requests/index.py @@ -32,22 +32,40 @@ def map_request(request): @requests_bp.route("/requests", methods=["GET"]) def requests_index(): - requests = [] - is_ccpo = Permissions.REVIEW_AND_APPROVE_JEDI_WORKSPACE_REQUEST in g.current_user.atat_permissions - if is_ccpo: - requests = Requests.get_many() - else: - requests = Requests.get_many(creator=g.current_user) + if Permissions.REVIEW_AND_APPROVE_JEDI_WORKSPACE_REQUEST in g.current_user.atat_permissions: + return _ccpo_view() + else: + return _non_ccpo_view() + + +def _ccpo_view(): + requests = Requests.get_many() mapped_requests = [map_request(r) for r in requests] - pending_fv = not is_ccpo and any(Requests.is_pending_financial_verification(r) for r in requests) - pending_ccpo = not is_ccpo and any(Requests.is_pending_ccpo_approval(r) for r in requests) + return render_template( + "requests.html", + requests=mapped_requests, + pending_financial_verification=False, + pending_ccpo_approval=False, + extended_view=True, + kpi_inprogress=Requests.in_progress_count(), + kpi_pending=Requests.pending_ccpo_count(), + kpi_completed=Requests.completed_count(), + ) + + +def _non_ccpo_view(): + requests = Requests.get_many(creator=g.current_user) + mapped_requests = [map_request(r) for r in requests] + + pending_fv = any(Requests.is_pending_financial_verification(r) for r in requests) + pending_ccpo = any(Requests.is_pending_ccpo_approval(r) for r in requests) return render_template( "requests.html", requests=mapped_requests, pending_financial_verification=pending_fv, pending_ccpo_approval=pending_ccpo, - extended_view=is_ccpo + extended_view=False, ) diff --git a/templates/requests.html b/templates/requests.html index 42d6ac1b..53950e10 100644 --- a/templates/requests.html +++ b/templates/requests.html @@ -51,16 +51,16 @@ {% if extended_view %}
-
3
-
Pending Requests
+
{{ kpi_inprogress }}
+
In Progress
-
2,456
-
Completed Requests This Year
+
{{ kpi_pending }}
+
Pending CCPO Action
-
234
-
Denied Requests
+
{{ kpi_completed }}
+
Completed (Overall)
{% endif %} diff --git a/tests/domain/test_requests.py b/tests/domain/test_requests.py index 420294e2..3e4e66e4 100644 --- a/tests/domain/test_requests.py +++ b/tests/domain/test_requests.py @@ -66,7 +66,7 @@ def test_exists(session): assert not Requests.exists(request.id, user_denied) -def test_count_status(session): +def test_status_count(session): # make sure table is empty session.query(Request).delete() @@ -74,5 +74,6 @@ def test_count_status(session): request2 = RequestFactory.create() RequestStatusEventFactory.create(sequence=2, request_id=request2.id, new_status=RequestStatus.PENDING_FINANCIAL_VERIFICATION) - assert Requests.count_status(RequestStatus.PENDING_FINANCIAL_VERIFICATION) == 1 - assert Requests.count_status(RequestStatus.STARTED) == 1 + assert Requests.status_count(RequestStatus.PENDING_FINANCIAL_VERIFICATION) == 1 + assert Requests.status_count(RequestStatus.STARTED) == 1 + assert Requests.in_progress_count() == 2