Move calc of a portfolio's obligated funds to prop

Add a property on the portfolio model to calculate the total
obligated funds for a portfolio. This replaces a one-off calculation
in a view function, and sets up functionality for future access
This commit is contained in:
graham-dds
2020-02-05 15:04:28 -05:00
parent 2f1c57aef4
commit 55736b723e
2 changed files with 8 additions and 8 deletions

View File

@@ -40,17 +40,11 @@ def reports(portfolio_id):
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(
task_order.total_obligated_funds
for task_order in portfolio.active_task_orders
)
)
return render_template(
"portfolios/reports/index.html",
portfolio=portfolio,
total_portfolio_value=total_portfolio_value,
# wrapped in str() because the sum of obligated funds returns a Decimal object
total_portfolio_value=str(portfolio.total_obligated_funds),
current_obligated_funds=current_obligated_funds,
expired_task_orders=Reports.expired_task_orders(portfolio),
monthly_spending=Reports.monthly_spending(portfolio),