Пример #1
0
def test_create_adds_clins():
    portfolio = PortfolioFactory.create()
    clins = [
        {
            "jedi_clin_type": "JEDI_CLIN_1",
            "number": "12312",
            "start_date": date(2020, 1, 1),
            "end_date": date(2021, 1, 1),
            "obligated_amount": Decimal("5000"),
            "total_amount": Decimal("10000"),
        },
        {
            "jedi_clin_type": "JEDI_CLIN_1",
            "number": "12312",
            "start_date": date(2020, 1, 1),
            "end_date": date(2021, 1, 1),
            "obligated_amount": Decimal("5000"),
            "total_amount": Decimal("10000"),
        },
    ]
    task_order = TaskOrders.create(
        creator=portfolio.owner,
        portfolio_id=portfolio.id,
        number="0123456789",
        clins=clins,
        pdf={
            "filename": "sample.pdf",
            "object_name": "1234567"
        },
    )
    assert len(task_order.clins) == 2
Пример #2
0
def test_update_adds_clins():
    task_order = TaskOrderFactory.create(number="1231231234")
    to_number = task_order.number
    clins = [
        {
            "jedi_clin_type": "JEDI_CLIN_1",
            "number": "12312",
            "start_date": date(2020, 1, 1),
            "end_date": date(2021, 1, 1),
            "obligated_amount": Decimal("5000"),
            "total_amount": Decimal("10000"),
        },
        {
            "jedi_clin_type": "JEDI_CLIN_1",
            "number": "12312",
            "start_date": date(2020, 1, 1),
            "end_date": date(2021, 1, 1),
            "obligated_amount": Decimal("5000"),
            "total_amount": Decimal("10000"),
        },
    ]
    task_order = TaskOrders.create(
        creator=task_order.creator,
        portfolio_id=task_order.portfolio_id,
        number="0000000000",
        clins=clins,
        pdf={
            "filename": "sample.pdf",
            "object_name": "1234567"
        },
    )
    assert task_order.number != to_number
    assert len(task_order.clins) == 2
Пример #3
0
def update_task_order(
    form_data, next_page, current_template, portfolio_id=None, task_order_id=None
):
    form = None
    if task_order_id:
        task_order = TaskOrders.get(task_order_id)
        form = TaskOrderForm(form_data, obj=task_order)
    else:
        form = TaskOrderForm(form_data)

    if form.validate():
        task_order = None
        if task_order_id:
            task_order = TaskOrders.update(task_order_id, **form.data)
            portfolio_id = task_order.portfolio_id
        else:
            task_order = TaskOrders.create(g.current_user, portfolio_id, **form.data)

        return redirect(url_for(next_page, task_order_id=task_order.id))
    else:
        return (
            render_task_orders_edit(
                current_template, portfolio_id, task_order_id, form
            ),
            400,
        )
Пример #4
0
def cancel_edit(task_order_id=None, portfolio_id=None):
    # Either save the currently entered data, or delete the TO
    save = http_request.args.get("save", "True").lower() == "true"

    if save:
        form_data = {**http_request.form}
        form = None
        if task_order_id:
            task_order = TaskOrders.get(task_order_id)
            form = TaskOrderForm(form_data, obj=task_order)
        else:
            form = TaskOrderForm(form_data)

        if form.validate(flash_invalid=False):
            task_order = None
            if task_order_id:
                task_order = TaskOrders.update(task_order_id, **form.data)
            else:
                task_order = TaskOrders.create(
                    g.current_user, portfolio_id, **form.data
                )
    elif not save and task_order_id:
        TaskOrders.delete(task_order_id)

    return redirect(
        url_for("task_orders.portfolio_funding", portfolio_id=g.portfolio.id)
    )
Пример #5
0
Файл: new.py Проект: v1psta/atst
def update_task_order(form, portfolio_id=None, task_order_id=None, flash_invalid=True):
    if form.validate(flash_invalid=flash_invalid):
        task_order = None
        try:
            if task_order_id:
                task_order = TaskOrders.update(task_order_id, **form.data)
                portfolio_id = task_order.portfolio_id
            else:
                task_order = TaskOrders.create(portfolio_id, **form.data)

            return task_order

        except AlreadyExistsError:
            flash("task_order_number_error", to_number=form.data["number"])
            return False
    else:
        return False
Пример #6
0
def test_create_enforces_unique_number():
    portfolio = PortfolioFactory.create()
    number = "1234567890123"
    assert TaskOrders.create(portfolio.id, number, [], None)
    with pytest.raises(AlreadyExistsError):
        TaskOrders.create(portfolio.id, number, [], None)