Flash message for insufficient funding
This commit is contained in:
parent
cde3d7f6aa
commit
3b265b0eb6
@ -25,12 +25,20 @@ class Reports:
|
||||
clin_spending[jedi_clin.name]["obligated"] = sum(
|
||||
clin.obligated_amount for clin in clins
|
||||
)
|
||||
return [
|
||||
|
||||
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": clin_spending[clin].get("invoiced", 0),
|
||||
"estimated": clin_spending[clin].get("estimated", 0),
|
||||
"obligated": clin_spending[clin].get("obligated", 0),
|
||||
"invoiced": invoiced,
|
||||
"estimated": estimated,
|
||||
"obligated": obligated,
|
||||
"remaining": remaining,
|
||||
}
|
||||
for clin in sorted(clin_spending.keys())
|
||||
]
|
||||
)
|
||||
return output
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
|
@ -96,6 +96,11 @@ MESSAGES = {
|
||||
"message_template": "<p>Please see below.</p>",
|
||||
"category": "error",
|
||||
},
|
||||
"insufficient_funds": {
|
||||
"title_template": "Insufficient Funds",
|
||||
"message_template": "",
|
||||
"category": "warning",
|
||||
},
|
||||
"logged_out": {
|
||||
"title_template": translate("flash.logged_out"),
|
||||
"message_template": """
|
||||
|
@ -5,7 +5,9 @@
|
||||
|
||||
{% block portfolio_content %}
|
||||
{{ StickyCTA("Reports") }}
|
||||
|
||||
<div class="portfolio-reports col col--grow">
|
||||
{% include "fragments/flash.html" %}
|
||||
<p class="row estimate-warning">{{ "portfolios.reports.estimate_warning" | translate }}</p>
|
||||
{% include "portfolios/reports/portfolio_summary.html" %}
|
||||
<hr>
|
||||
|
@ -7,15 +7,14 @@
|
||||
</header>
|
||||
<div class='panel'>
|
||||
<div class='panel__content jedi-clin-funding'>
|
||||
{% 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')%}
|
||||
<div class="jedi-clin-funding__clin-wrapper">
|
||||
<h3 class="h5 jedi-clin-funding__header">
|
||||
{{ "JEDICLINType.{}".format(JEDI_clin.name) | translate }}
|
||||
</h3>
|
||||
<p class="jedi-clin-funding__subheader">Total obligated amount: {{ JEDI_clin.obligated | dollars }}</p>
|
||||
<div class="jedi-clin-funding__graph">
|
||||
{% if remaining_funds < 0 %}
|
||||
{% if JEDI_clin.remaining < 0 %}
|
||||
<span style="width:100%" class="jedi-clin-funding__graph-bar jedi-clin-funding__graph-bar--insufficient"></span>
|
||||
{% 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">
|
||||
</span>
|
||||
{% endif %}
|
||||
<span style="width:{{ (remaining_funds, JEDI_clin.obligated) | obligatedFundingGraphWidth }}%"
|
||||
<span style="width:{{ (JEDI_clin.remaining, JEDI_clin.obligated) | obligatedFundingGraphWidth }}%"
|
||||
class="jedi-clin-funding__graph-bar jedi-clin-funding__graph-bar--remaining">
|
||||
</span>
|
||||
{% endif %}
|
||||
@ -55,10 +54,10 @@
|
||||
</div>
|
||||
<div class="jedi-clin-funding__meta">
|
||||
<p class="jedi-clin-funding__meta-header">
|
||||
<span class="jedi-clin-funding__meta-key jedi-clin-funding__meta-key--{{"remaining" if remaining_funds > 0 else "insufficient"}}"></span>
|
||||
<span class="jedi-clin-funding__meta-key jedi-clin-funding__meta-key--{{"remaining" if JEDI_clin.remaining > 0 else "insufficient"}}"></span>
|
||||
Remaining funds:
|
||||
</p>
|
||||
<p class="h3 jedi-clin-funding__meta-value {% if remaining_funds < 0 %}text-danger{% endif %}">{{ remaining_funds | dollars }}</p>
|
||||
<p class="h3 jedi-clin-funding__meta-value {% if JEDI_clin.remaining < 0 %}text-danger{% endif %}">{{ JEDI_clin.remaining | dollars }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user