diff --git a/atst/domain/reports.py b/atst/domain/reports.py index 22760ec9..99b229e3 100644 --- a/atst/domain/reports.py +++ b/atst/domain/reports.py @@ -25,12 +25,20 @@ class Reports: clin_spending[jedi_clin.name]["obligated"] = sum( clin.obligated_amount for clin in clins ) - return [ - { - "name": clin, - "invoiced": clin_spending[clin].get("invoiced", 0), - "estimated": clin_spending[clin].get("estimated", 0), - "obligated": clin_spending[clin].get("obligated", 0), - } - for clin in sorted(clin_spending.keys()) - ] + + output = [] + for clin in clin_spending.keys(): + invoiced = clin_spending[clin].get("invoiced", 0) + estimated = clin_spending[clin].get("estimated", 0) + obligated = clin_spending[clin].get("obligated", 0) + remaining = obligated - (invoiced + estimated) + output.append( + { + "name": clin, + "invoiced": invoiced, + "estimated": estimated, + "obligated": obligated, + "remaining": remaining, + } + ) + return output diff --git a/atst/routes/portfolios/index.py b/atst/routes/portfolios/index.py index 8787c4f6..67831c9c 100644 --- a/atst/routes/portfolios/index.py +++ b/atst/routes/portfolios/index.py @@ -35,6 +35,12 @@ def create_portfolio(): @user_can(Permissions.VIEW_PORTFOLIO_REPORTS, message="view portfolio reports") def reports(portfolio_id): portfolio = Portfolios.get(g.current_user, portfolio_id) + + current_obligated_funds = Reports.obligated_funds_by_JEDI_clin(portfolio) + + if any(map(lambda clin: clin["remaining"] < 0, current_obligated_funds)): + flash("insufficient_funds") + # wrapped in str() because the sum of obligated funds returns a Decimal object total_portfolio_value = str( sum( @@ -46,11 +52,9 @@ def reports(portfolio_id): "portfolios/reports/index.html", portfolio=portfolio, total_portfolio_value=total_portfolio_value, - current_obligated_funds=Reports.obligated_funds_by_JEDI_clin(portfolio), + current_obligated_funds=current_obligated_funds, expired_task_orders=Reports.expired_task_orders(portfolio), monthly_spending=Reports.monthly_spending(portfolio), - current_month=current_month, - prev_month=prev_month, retrieved=datetime.now(), # mocked datetime of reporting data retrival ) diff --git a/atst/utils/flash.py b/atst/utils/flash.py index 73bdbc4c..87b543b8 100644 --- a/atst/utils/flash.py +++ b/atst/utils/flash.py @@ -96,6 +96,11 @@ MESSAGES = { "message_template": "

Please see below.

", "category": "error", }, + "insufficient_funds": { + "title_template": "Insufficient Funds", + "message_template": "", + "category": "warning", + }, "logged_out": { "title_template": translate("flash.logged_out"), "message_template": """ diff --git a/templates/portfolios/reports/index.html b/templates/portfolios/reports/index.html index 8f2fad93..747610d9 100644 --- a/templates/portfolios/reports/index.html +++ b/templates/portfolios/reports/index.html @@ -5,7 +5,9 @@ {% block portfolio_content %} {{ StickyCTA("Reports") }} +
+ {% include "fragments/flash.html" %}

{{ "portfolios.reports.estimate_warning" | translate }}

{% include "portfolios/reports/portfolio_summary.html" %}
diff --git a/templates/portfolios/reports/obligated_funds.html b/templates/portfolios/reports/obligated_funds.html index fda6eda1..43046472 100644 --- a/templates/portfolios/reports/obligated_funds.html +++ b/templates/portfolios/reports/obligated_funds.html @@ -7,15 +7,14 @@
- {% for JEDI_clin in current_obligated_funds %} - {% set remaining_funds = JEDI_clin.obligated - (JEDI_clin.invoiced + JEDI_clin.estimated) %} + {% for JEDI_clin in current_obligated_funds | sort(attribute='name')%}

{{ "JEDICLINType.{}".format(JEDI_clin.name) | translate }}

Total obligated amount: {{ JEDI_clin.obligated | dollars }}

- {% if remaining_funds < 0 %} + {% if JEDI_clin.remaining < 0 %} {% else %} {% set invoiced_width = (JEDI_clin.invoiced, JEDI_clin.obligated) | obligatedFundingGraphWidth %} @@ -31,7 +30,7 @@ class="jedi-clin-funding__graph-bar jedi-clin-funding__graph-bar--estimated"> {% endif %} - {% endif %} @@ -55,10 +54,10 @@

- 0 else "insufficient"}}"> + 0 else "insufficient"}}"> Remaining funds:

-

{{ remaining_funds | dollars }}

+

{{ JEDI_clin.remaining | dollars }}