Пример #1
0
def edit_outgoing_handler(outgoing_id):
    user = User.query.get(session["user_id"])

    form_data = h.empty_strings_to_none(request.form)

    outgoing = Outgoing.query.filter_by(
        user_id=user.id, id=outgoing_id
    ).first()

    outgoing.account_id = form_data["account_id"]
    outgoing.name = form_data["name"]
    outgoing.value = form_data["value"]
    outgoing.start_month = h.month_input_to_date(form_data.get("start_month"))
    outgoing.end_month = h.month_input_to_date(
        form_data.get("end_month"), set_to_last_day=True
    )

    outgoing.linked_saving_id = form_data.get("linked_saving_id")
    outgoing.is_self_loan = h.checkbox_to_boolean(
        form_data.get("is_self_loan")
    )

    outgoing.notes = form_data["notes"]

    db.session.commit()

    return redirect(url_for("outgoings"))
Пример #2
0
def new_account_handler():
    user = User.query.get(session["user_id"])

    form_data = h.empty_strings_to_none(request.form)

    db.session.add(Account(user.id, form_data["name"], form_data["notes"]))
    db.session.commit()

    return redirect(url_for("accounts"))
Пример #3
0
def configuration_handler():
    user = User.query.get(session["user_id"])

    form_data = h.empty_strings_to_none(request.form)

    form_data["month_start_date"] = 28  # Hardcode for now.

    if user.configuration is None:
        db.session.add(
            Configuration(
                user.id,
                form_data["weekly_pay_day"],
                form_data["weekly_spending_amount"],
                form_data["annual_expense_outgoing_id"],
                form_data["starling_api_key"],
            )
        )
    else:
        user.configuration.weekly_pay_day = form_data["weekly_pay_day"]
        user.configuration.weekly_spending_amount = form_data[
            "weekly_spending_amount"
        ]
        user.configuration.annual_expense_outgoing_id = form_data[
            "annual_expense_outgoing_id"
        ]
        user.configuration.starling_api_key = form_data["starling_api_key"]

    if user.salary is None:
        db.session.add(
            Salary(
                user.id,
                form_data["annual_gross_salary"],
                form_data["annual_tax_allowance"],
                form_data["tax_rate"],
                form_data["annual_ni_allowance"],
                form_data["ni_rate"],
                form_data["annual_non_pensionable_value"],
                form_data["pension_contribution"],
            )
        )
    else:
        user.salary.annual_gross_salary = form_data["annual_gross_salary"]
        user.salary.annual_tax_allowance = form_data["annual_tax_allowance"]
        user.salary.tax_rate = form_data["tax_rate"]
        user.salary.annual_ni_allowance = form_data["annual_ni_allowance"]
        user.salary.ni_rate = form_data["ni_rate"]
        user.salary.annual_non_pensionable_value = form_data[
            "annual_non_pensionable_value"
        ]
        user.salary.pension_contribution = form_data["pension_contribution"]

    db.session.commit()

    AnnualExpense.update_user_annual_expense_outgoing(user)

    return redirect(url_for(form_data.get("return_page", "index")))
Пример #4
0
def edit_account_handler(account_id):
    user = User.query.get(session["user_id"])

    form_data = h.empty_strings_to_none(request.form)

    account = Account.query.filter_by(user_id=user.id, id=account_id).first()

    account.name = form_data["name"]
    account.notes = form_data["notes"]

    db.session.commit()

    return redirect(url_for("accounts"))
Пример #5
0
def new_saving_handler():
    user = User.query.get(session["user_id"])

    form_data = h.empty_strings_to_none(request.form)

    db.session.add(
        Saving(
            user.id,
            form_data["name"],
            form_data["balance"],
            form_data["notes"],
        )
    )
    db.session.commit()

    return redirect(url_for("savings"))
Пример #6
0
def configuration_handler():
    user = User.query.get(session["user_id"])

    form_data = h.empty_strings_to_none(request.form)

    if user.configuration is None:
        db.session.add(
            Configuration(
                user.id,
                form_data["annual_expense_outgoing_id"],
                emergency_fund_months=form_data["emergency_fund_months"],
            ))
    else:
        user.configuration.annual_expense_outgoing_id = form_data[
            "annual_expense_outgoing_id"]
        user.configuration.emergency_fund_months = form_data[
            "emergency_fund_months"]

    if user.salary is None:
        db.session.add(
            Salary(
                user.id,
                form_data["annual_gross_salary"],
                form_data["annual_tax_allowance"],
                form_data["tax_rate"],
                form_data["annual_ni_allowance"],
                form_data["ni_rate"],
                form_data["annual_non_pensionable_value"],
                form_data["pension_contribution"],
            ))
    else:
        user.salary.annual_gross_salary = form_data["annual_gross_salary"]
        user.salary.annual_tax_allowance = form_data["annual_tax_allowance"]
        user.salary.tax_rate = form_data["tax_rate"]
        user.salary.annual_ni_allowance = form_data["annual_ni_allowance"]
        user.salary.ni_rate = form_data["ni_rate"]
        user.salary.annual_non_pensionable_value = form_data[
            "annual_non_pensionable_value"]
        user.salary.pension_contribution = form_data["pension_contribution"]

    db.session.commit()

    AnnualExpense.update_user_annual_expense_outgoing(user)

    return redirect(url_for(form_data.get("return_page", "index")))
Пример #7
0
def edit_saving_handler(saving_id):
    user = User.query.get(session["user_id"])

    form_data = h.empty_strings_to_none(request.form)

    saving = Saving.query.filter_by(user_id=user.id, id=saving_id).first()

    saving.name = form_data["name"]

    if int(saving.balance * 100) != int(float(form_data["balance"]) * 100):
        saving.balance = form_data["balance"]
        saving.last_manual_update = date.today()

    saving.notes = form_data["notes"]

    db.session.commit()

    return redirect(url_for("savings"))
Пример #8
0
def edit_annual_expense_handler(annual_expense_id):
    user = User.query.get(session["user_id"])

    form_data = h.empty_strings_to_none(request.form)

    annual_expense = AnnualExpense.query.filter_by(
        user_id=user.id, id=annual_expense_id).first()

    annual_expense.month_paid = form_data["month_paid"]
    annual_expense.name = form_data["name"]
    annual_expense.value = form_data["value"]
    annual_expense.notes = form_data["notes"]

    db.session.commit()

    AnnualExpense.update_user_annual_expense_outgoing(user)

    return redirect(url_for("annual_expenses"))
Пример #9
0
def new_annual_expense_handler():
    user = User.query.get(session["user_id"])

    form_data = h.empty_strings_to_none(request.form)

    db.session.add(
        AnnualExpense(
            user.id,
            form_data["month_paid"],
            form_data["name"],
            form_data["value"],
            form_data["notes"],
        ))
    db.session.commit()

    AnnualExpense.update_user_annual_expense_outgoing(user)

    return redirect(url_for("annual_expenses"))
Пример #10
0
def new_outgoing_handler():
    user = User.query.get(session["user_id"])

    form_data = h.empty_strings_to_none(request.form)

    db.session.add(
        Outgoing(
            user.id,
            form_data["name"],
            form_data["value"],
            form_data["account_id"],
            start_month=h.month_input_to_date(form_data["start_month"]),
            end_month=h.month_input_to_date(form_data["end_month"],
                                            set_to_last_day=True),
            notes=form_data["notes"],
            emergency_fund_excluded=h.checkbox_to_boolean(
                form_data.get("emergency_fund_excluded")),
        ))
    db.session.commit()

    return redirect(url_for("outgoings"))