Merge pull request #690 from dod-ccpo/update-demo-data
Update demo data
This commit is contained in:
commit
03ee3438fd
@ -101,32 +101,48 @@ def get_users():
|
|||||||
return users
|
return users
|
||||||
|
|
||||||
|
|
||||||
def add_members_to_portfolio(portfolio, users):
|
def add_members_to_portfolio(portfolio):
|
||||||
for user in users:
|
get_users()
|
||||||
for portfolio_role in PORTFOLIO_USERS:
|
for portfolio_role in PORTFOLIO_USERS:
|
||||||
ws_role = Portfolios.create_member(
|
ws_role = Portfolios.create_member(portfolio.owner, portfolio, portfolio_role)
|
||||||
portfolio.owner, portfolio, portfolio_role
|
db.session.refresh(ws_role)
|
||||||
)
|
PortfolioRoles.enable(ws_role)
|
||||||
db.session.refresh(ws_role)
|
|
||||||
PortfolioRoles.enable(ws_role)
|
|
||||||
|
|
||||||
for portfolio_role in PORTFOLIO_INVITED_USERS:
|
|
||||||
ws_role = Portfolios.create_member(
|
|
||||||
portfolio.owner, portfolio, portfolio_role
|
|
||||||
)
|
|
||||||
invitation = InvitationFactory.build(
|
|
||||||
portfolio_role=ws_role, status=portfolio_role["status"]
|
|
||||||
)
|
|
||||||
db.session.add(invitation)
|
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
def add_active_task_order(portfolio, active_exp_days=90, clin_01=None, clin_03=None):
|
def invite_members_to_portfolio(portfolio):
|
||||||
start = random_past_date(year_max=1, year_min=1)
|
get_users()
|
||||||
|
for portfolio_role in PORTFOLIO_INVITED_USERS:
|
||||||
|
ws_role = Portfolios.create_member(portfolio.owner, portfolio, portfolio_role)
|
||||||
|
invitation = InvitationFactory.build(
|
||||||
|
portfolio_role=ws_role, status=portfolio_role["status"]
|
||||||
|
)
|
||||||
|
db.session.add(invitation)
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def add_task_orders_to_portfolio(portfolio, to_length=90, clin_01=None, clin_03=None):
|
||||||
|
active_to_offset = random.randint(10, 31)
|
||||||
|
# exp TO ends same day as active TO starts
|
||||||
|
active_start = date.today() - timedelta(days=active_to_offset)
|
||||||
|
# pending TO starts the same day active TO ends
|
||||||
|
active_end = active_start + timedelta(to_length)
|
||||||
|
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 +159,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,10 +186,8 @@ 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_members_to_portfolio(portfolio)
|
||||||
add_pending_task_order(portfolio)
|
|
||||||
add_members_to_portfolio(portfolio, users=get_users())
|
|
||||||
|
|
||||||
for mock_application in data["applications"]:
|
for mock_application in data["applications"]:
|
||||||
application = Application(
|
application = Application(
|
||||||
@ -211,7 +200,6 @@ def create_demo_portfolio(name, data):
|
|||||||
|
|
||||||
|
|
||||||
def seed_db():
|
def seed_db():
|
||||||
users = get_users()
|
|
||||||
amanda = Users.get_by_dod_id("2345678901")
|
amanda = Users.get_by_dod_id("2345678901")
|
||||||
application_info = [
|
application_info = [
|
||||||
{
|
{
|
||||||
@ -225,34 +213,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)
|
||||||
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)
|
||||||
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 get_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_members_to_portfolio(portfolio, users=users)
|
add_task_orders_to_portfolio(portfolio)
|
||||||
add_active_task_order(portfolio)
|
add_members_to_portfolio(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