示例#1
0
def create_costcode_post():
    project = flask.request.args.get("project")
    # get list of costcode data
    current_costcodes = costcode_services.get_costcodes(project)
    form = CreateCostcodeForm()
    data = {
        "project_code": project,
        "costcode": form.costcode.data,
        "costcode_description": form.costcode_description.data,
        "costcode_category": form.costcode_category.data,
    }
    if form.validate_on_submit():
        # check if the costcode already exists for the project_code
        if costcode_services.check_if_costcode_exists(
                project_code=project, costcode=form.costcode.data):
            flask.flash("Costcode " + form.costcode.data + " already exists",
                        "alert-danger")
        else:
            # commit the data to the database
            admin_services.create_costcode(data)
            flask.flash("Costcode " + form.costcode.data + " created",
                        "alert-success")
            return flask.redirect(
                flask.url_for("create_costcode.create_costcode_get",
                              project=project))
    return flask.render_template(
        "admin/create_costcode.html",
        form=form,
        project=project,
        current_costcodes=current_costcodes,
    )
示例#2
0
def costcodes_view(project):
    project_details = project_view_services.get_project_details(project)
    project_costcode_detail = costcode_services.get_costcodes(project)
    project_financial_summary = project_view_services.get_project_financial_summary(
        project)
    return flask.render_template(
        "project/costcodes.html",
        project_details=project_details,
        project_costcode_detail=project_costcode_detail,
        project_financial_summary=project_financial_summary,
    )
示例#3
0
def create_costcode_get():
    project_code = flask.request.args.get("project")
    # check if project exists
    if projects_service.check_if_project_exists(project_code) is False:
        flask.abort(404)
    form = CreateCostcodeForm()
    # get list of costcode data
    current_costcodes = costcode_services.get_costcodes(project_code)
    return flask.render_template(
        "admin/create_costcode.html",
        form=form,
        project_code=project_code,
        current_costcodes=current_costcodes,
    )
示例#4
0
 def test_check_default_costcodes_are_added_to_project(self):
     costcodes = costcode_services.get_costcodes("65432")
     assert costcodes[0].costcode == "0"
     assert costcodes[1].costcode == "20000"
示例#5
0
 def test_get_all_costcodes(self):
     assert len(costcode_services.get_costcodes("12345")) == 3
     assert costcode_services.get_costcodes("12345")[0].costcode == "C1000"
     assert costcode_services.get_costcodes("12345")[1].costcode == "C2000"
     assert costcode_services.get_costcodes("12345")[1].costcode == "C2000"