Exemple #1
0
def add_income():
    form = IncomeForm()
    users = User.query.filter_by(bmID=current_user.bmID)
    form.owner.choices = [(user.id, user.firstname) for user in users]
    banks = Bank.query.filter_by(bmID=current_user.bmID, accounttype="Current")
    form.paidinto.choices = [(bank.bankID,
                              bank.bankname + " - " + bank.accounttype)
                             for bank in banks]
    if form.validate_on_submit():
        new_income = Income(bmID=current_user.bmID,
                            owner=form.owner.data,
                            amount=form.amount.data,
                            frequency=form.frequency.data,
                            paidinto=form.paidinto.data,
                            nextduedate=form.nextduedate.data)
        db.session.add(new_income)
        db.session.commit()
        return redirect(url_for("view_incomes"))
    return render_template("add-income.html", form=form)
Exemple #2
0
def edit_income(income_id):
    income = Income.query.get(income_id)
    edit_form = IncomeForm(owner=get_member_name(income.owner),
                           amount=income.amount,
                           frequency=income.frequency,
                           paidinto=get_bank_name(income.paidinto),
                           nextduedate=income.nextduedate)
    users = User.query.filter_by(bmID=current_user.bmID)
    edit_form.owner.choices = [(user.id, user.firstname) for user in users]
    banks = Bank.query.filter_by(bmID=current_user.bmID, accounttype="Current")
    edit_form.paidinto.choices = [(bank.bankID,
                                   bank.bankname + " - " + bank.accounttype)
                                  for bank in banks]
    if edit_form.validate_on_submit():
        income.owner = edit_form.owner.data,
        income.amount = edit_form.amount.data,
        income.frequency = edit_form.frequency.data,
        income.paidinto = edit_form.paidinto.data,
        income.nextduedate = edit_form.nextduedate.data
        db.session.commit()
        return redirect(url_for("view_income"))
    return render_template("add-income.html", form=edit_form)