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:
parent
2f1c57aef4
commit
55736b723e
@ -89,6 +89,12 @@ class Portfolio(
|
|||||||
def active_task_orders(self):
|
def active_task_orders(self):
|
||||||
return [task_order for task_order in self.task_orders if task_order.is_active]
|
return [task_order for task_order in self.task_orders if task_order.is_active]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def total_obligated_funds(self):
|
||||||
|
return sum(
|
||||||
|
(task_order.total_obligated_funds for task_order in self.active_task_orders)
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def funding_duration(self):
|
def funding_duration(self):
|
||||||
"""
|
"""
|
||||||
|
@ -40,17 +40,11 @@ def reports(portfolio_id):
|
|||||||
if any(map(lambda clin: clin["remaining"] < 0, current_obligated_funds)):
|
if any(map(lambda clin: clin["remaining"] < 0, current_obligated_funds)):
|
||||||
flash("insufficient_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(
|
return render_template(
|
||||||
"portfolios/reports/index.html",
|
"portfolios/reports/index.html",
|
||||||
portfolio=portfolio,
|
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,
|
current_obligated_funds=current_obligated_funds,
|
||||||
expired_task_orders=Reports.expired_task_orders(portfolio),
|
expired_task_orders=Reports.expired_task_orders(portfolio),
|
||||||
monthly_spending=Reports.monthly_spending(portfolio),
|
monthly_spending=Reports.monthly_spending(portfolio),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user