Add properties to portfolio model
1. Funding duration Returns a tuple of the earliest period of performance start date and latest period of performance end date for all active task order in a portfolio. 2. Days to funding expiration Returns the numbei of days between today and the lastest period performance end date of all active task orders 3. Active task orders Returns a list of a portfolio's active task orders a
This commit is contained in:
@@ -74,6 +74,49 @@ class Portfolio(
|
||||
if clin.is_active
|
||||
]
|
||||
|
||||
@property
|
||||
def active_task_orders(self):
|
||||
return [task_order for task_order in self.task_orders if task_order.is_active]
|
||||
|
||||
@property
|
||||
def funding_duration(self):
|
||||
"""
|
||||
Return the earliest period of performance start date and latest period
|
||||
of performance end date for all active task orders in a portfolio.
|
||||
@return: (datetime.date or None, datetime.date or None)
|
||||
"""
|
||||
start_dates = (
|
||||
task_order.start_date
|
||||
for task_order in self.task_orders
|
||||
if task_order.is_active
|
||||
)
|
||||
|
||||
end_dates = (
|
||||
task_order.end_date
|
||||
for task_order in self.task_orders
|
||||
if task_order.is_active
|
||||
)
|
||||
|
||||
earliest_pop_start_date = min(start_dates, default=None)
|
||||
latest_pop_end_date = max(end_dates, default=None)
|
||||
|
||||
return (earliest_pop_start_date, latest_pop_end_date)
|
||||
|
||||
@property
|
||||
def days_to_funding_expiration(self):
|
||||
"""
|
||||
Returns the number of days between today and the lastest period performance
|
||||
end date of all active Task Orders
|
||||
"""
|
||||
return max(
|
||||
(
|
||||
task_order.days_to_expiration
|
||||
for task_order in self.task_orders
|
||||
if task_order.is_active
|
||||
),
|
||||
default=None,
|
||||
)
|
||||
|
||||
@property
|
||||
def members(self):
|
||||
return (
|
||||
|
Reference in New Issue
Block a user