Add in start and end dates to creating TOs and refactor to create all TOs at once so they can have overlapping start/end dates
This commit is contained in:
parent
70617938d8
commit
b82b5bb9c0
@ -122,11 +122,22 @@ def add_members_to_portfolio(portfolio, users):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
def add_active_task_order(portfolio, active_exp_days=90, clin_01=None, clin_03=None):
|
def add_task_orders_to_portfolio(portfolio, to_length=90, clin_01=None, clin_03=None):
|
||||||
start = random_past_date(year_max=1, year_min=1)
|
active_to_offset = random.randint(10,31)
|
||||||
|
active_start = (date.today() - timedelta(days=active_to_offset)) # exp TO ends same day as active TO starts
|
||||||
|
active_end = (active_start + timedelta(to_length)) # pending TO starts the same day active TO ends
|
||||||
|
pending_end = (active_end + timedelta(to_length))
|
||||||
|
exp_start = (active_start - timedelta(to_length))
|
||||||
|
|
||||||
|
create_task_order(portfolio, start=exp_start, end=active_start)
|
||||||
|
create_task_order(portfolio, start=active_start, end=active_end, clin_01=clin_01, clin_03=clin_03)
|
||||||
|
create_task_order(portfolio, start=active_end, end=pending_end)
|
||||||
|
|
||||||
|
|
||||||
|
def create_task_order(portfolio, start, end, clin_01=None, clin_03=None):
|
||||||
default_kwargs = {
|
default_kwargs = {
|
||||||
"start_date": start,
|
"start_date": start,
|
||||||
"end_date": (date.today() + timedelta(days=active_exp_days)),
|
"end_date": end,
|
||||||
"number": random_task_order_number(),
|
"number": random_task_order_number(),
|
||||||
"portfolio": portfolio,
|
"portfolio": portfolio,
|
||||||
"clin_02": 0,
|
"clin_02": 0,
|
||||||
@ -143,31 +154,6 @@ def add_active_task_order(portfolio, active_exp_days=90, clin_01=None, clin_03=N
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
def add_expired_task_order(portfolio):
|
|
||||||
start = random_past_date(year_max=3, year_min=2)
|
|
||||||
task_order = TaskOrderFactory.build(
|
|
||||||
start_date=start,
|
|
||||||
end_date=(start + timedelta(days=90)),
|
|
||||||
number=random_task_order_number(),
|
|
||||||
portfolio=portfolio,
|
|
||||||
)
|
|
||||||
db.session.add(task_order)
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
|
|
||||||
def add_pending_task_order(portfolio):
|
|
||||||
start_date = random_future_date(year_min=1, year_max=2)
|
|
||||||
|
|
||||||
task_order = TaskOrderFactory.build(
|
|
||||||
start_date=start_date,
|
|
||||||
end_date=(start_date + timedelta(days=90)),
|
|
||||||
number=random_task_order_number(),
|
|
||||||
portfolio=portfolio,
|
|
||||||
)
|
|
||||||
db.session.add(task_order)
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
|
|
||||||
def add_applications_to_portfolio(portfolio, applications):
|
def add_applications_to_portfolio(portfolio, applications):
|
||||||
for application in applications:
|
for application in applications:
|
||||||
Applications.create(
|
Applications.create(
|
||||||
@ -195,9 +181,7 @@ def create_demo_portfolio(name, data):
|
|||||||
clin_01 = data["budget"] * 0.8
|
clin_01 = data["budget"] * 0.8
|
||||||
clin_03 = data["budget"] * 0.2
|
clin_03 = data["budget"] * 0.2
|
||||||
|
|
||||||
add_active_task_order(portfolio, clin_01=clin_01, clin_03=clin_03)
|
add_task_orders_to_portfolio(portfolio, clin_01=clin_01, clin_03=clin_03)
|
||||||
add_expired_task_order(portfolio)
|
|
||||||
add_pending_task_order(portfolio)
|
|
||||||
add_members_to_portfolio(portfolio, users=get_users())
|
add_members_to_portfolio(portfolio, users=get_users())
|
||||||
|
|
||||||
for mock_application in data["applications"]:
|
for mock_application in data["applications"]:
|
||||||
@ -225,34 +209,27 @@ def seed_db():
|
|||||||
create_demo_portfolio("A-Wing", MockReportingProvider.REPORT_FIXTURE_MAP["A-Wing"])
|
create_demo_portfolio("A-Wing", MockReportingProvider.REPORT_FIXTURE_MAP["A-Wing"])
|
||||||
create_demo_portfolio("B-Wing", MockReportingProvider.REPORT_FIXTURE_MAP["B-Wing"])
|
create_demo_portfolio("B-Wing", MockReportingProvider.REPORT_FIXTURE_MAP["B-Wing"])
|
||||||
|
|
||||||
# Create Portfolio for Amanda with TO that is expiring soon and does not have another TO
|
tie_interceptor = Portfolios.create(
|
||||||
unfunded_portfolio = Portfolios.create(
|
|
||||||
amanda, name="TIE Interceptor", defense_component=random_service_branch()
|
amanda, name="TIE Interceptor", defense_component=random_service_branch()
|
||||||
)
|
)
|
||||||
add_active_task_order(unfunded_portfolio, active_exp_days=20)
|
add_task_orders_to_portfolio(tie_interceptor)
|
||||||
add_expired_task_order(unfunded_portfolio)
|
add_members_to_portfolio(tie_interceptor, users=users)
|
||||||
add_members_to_portfolio(unfunded_portfolio, users=users)
|
add_applications_to_portfolio(tie_interceptor, application_info)
|
||||||
add_applications_to_portfolio(unfunded_portfolio, application_info)
|
|
||||||
|
|
||||||
# Create Portfolio for Amanda with TO that is expiring soon and has another TO
|
tie_fighter = Portfolios.create(
|
||||||
funded_portfolio = Portfolios.create(
|
|
||||||
amanda, name="TIE Fighter", defense_component=random_service_branch()
|
amanda, name="TIE Fighter", defense_component=random_service_branch()
|
||||||
)
|
)
|
||||||
add_active_task_order(funded_portfolio, active_exp_days=20)
|
add_task_orders_to_portfolio(tie_fighter)
|
||||||
add_expired_task_order(funded_portfolio)
|
add_members_to_portfolio(tie_fighter, users=users)
|
||||||
add_pending_task_order(funded_portfolio)
|
add_applications_to_portfolio(tie_fighter, application_info)
|
||||||
add_members_to_portfolio(funded_portfolio, users=users)
|
|
||||||
add_applications_to_portfolio(funded_portfolio, application_info)
|
|
||||||
|
|
||||||
# create a portfolio 'Y-Wing' for each user
|
# create a portfolio 'Y-Wing' for each user
|
||||||
for user in users:
|
for user in users:
|
||||||
portfolio = Portfolios.create(
|
portfolio = Portfolios.create(
|
||||||
user, name="Y-Wing", defense_component=random_service_branch()
|
user, name="Y-Wing", defense_component=random_service_branch()
|
||||||
)
|
)
|
||||||
|
add_task_orders_to_portfolio(portfolio)
|
||||||
add_members_to_portfolio(portfolio, users=users)
|
add_members_to_portfolio(portfolio, users=users)
|
||||||
add_active_task_order(portfolio)
|
|
||||||
add_expired_task_order(portfolio)
|
|
||||||
add_pending_task_order(portfolio)
|
|
||||||
add_applications_to_portfolio(portfolio, application_info)
|
add_applications_to_portfolio(portfolio, application_info)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user