示例#1
0
def create_test_transaction(
    user_id,
    title='Test Transaction',
    date=datetime.now(),
    amount=100.00,
    description='Test Description',
    income=False,
    is_recurring=False,
    freq=None,
    interval=None,
    count=None,
    until=None,
):
    t = Transaction(
        user_id=user_id,
        title=title,
        date=date,
        income=income,
        is_recurring=is_recurring,
        freq=freq,
        interval=interval,
        count=count,
        until=until,
    )
    t.set_amount(amount)
    if is_recurring:
        t.set_recurring(None)
    db.session.add(t)
    db.session.commit()
    return Transaction.query.filter_by(id=t.id).first()
示例#2
0
 def createTestTransaction(
     self,
     user_id,
     title='Test Transaction',
     date=datetime.now(),
     amount=100.00,
     income=False,
     is_recurring=False,
 ):
     t = Transaction(user_id=user_id,
                     title=title,
                     date=date,
                     income=income,
                     is_recurring=is_recurring)
     t.set_amount(amount)
     db.session.add(t)
     db.session.commit()
     return Transaction.query.filter_by(id=t.id).first()
示例#3
0
def add_transaction():
    form = TransactionForm(request.form)
    if request.method == 'POST':
        if 'cancel' in request.form.keys():
            year = 0
            month = 0
            flash("Add cancelled.")
        elif form.validate():
            year = form.date.data.year
            month = form.date.data.month
            transaction = Transaction(
                user_id=current_user.id,
                title=form.title.data,
                date=form.date.data,
                description=form.description.data,
                income=form.income.data,
                is_recurring=form.is_recurring.data,
                freq=form.freq.data,
                interval=form.interval.data,
                count=form.count.data,
                until=form.until.data,
            )
            transaction.set_amount(form.amount.data)
            if form.is_recurring.data:
                transaction.set_recurring(form.byweekday.data)
            db.session.add(transaction)
            db.session.commit()
            flash("Transaction added.")
        return redirect(url_for(
            "main.index",
            year=year,
            month=month,
        ))

    return render_template(
        "transaction.html",
        title="Add Transaction",
        form=form,
    )
示例#4
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User(
            username=form.username.data,
            email=form.email.data,
            start_date=form.start_date.data,
        )
        user.set_start_balance(form.start_balance.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()

        row = User.query.filter_by(username=form.username.data).first()

        transaction = Transaction(
            user_id=row.id,
            title="Initial Balance", 
            date=form.start_date.data,
            description="Initial Balance",
            income=True,
            is_recurring=False,
        )
        transaction.set_amount(form.start_balance.data)
        db.session.add(transaction)
        db.session.commit()

        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('auth.login'))
        
    return render_template(
        'auth/register.html',
        title='Register',
        form=form,
    )
示例#5
0
def edit_the_transaction(form, edited_transaction, current_date):
    if form.is_recurring.data and form.change.data == 'current':
        if form.amount.data != edited_transaction.amount:
            added_transaction = Transaction(
                title=form.title.data,
                description=form.description.data,
                income=form.income.data,
                is_recurring=False,
                freq=form.freq.data,
                interval=form.interval.data,
                count=form.count.data,
                until=form.until.data,
            )
            added_transaction.set_amount(form.amount.data)
            added_transaction.set_recurring(form.byweekday.data)
        else:
            added_transaction = TransactionException(
                delete=False,
                transaction_id=edited_transaction.id,
            )
        added_transaction.date = form.date.data
        added_transaction.user_id = current_user.id
        db.session.add(added_transaction)
        removed_transaction = TransactionException(
            date=current_date,
            delete=True,
            transaction_id=edited_transaction.id,
            user_id=current_user.id,
        )
        db.session.add(removed_transaction)
    elif form.is_recurring.data and form.change.data == 'after':
        added_transaction = Transaction(
            user_id=current_user.id,
            title=form.title.data,
            date=form.date.data,
            description=form.description.data,
            income=form.income.data,
            is_recurring=form.is_recurring.data,
            freq=form.freq.data,
            interval=form.interval.data,
            count=form.count.data,
            until=form.until.data,
            transaction_exceptions=edited_transaction.transaction_exceptions,
        )
        added_transaction.set_amount(form.amount.data)
        added_transaction.set_recurring(form.byweekday.data)
        db.session.add(added_transaction)
        edited_transaction.count = None
        edited_transaction.until = current_date - timedelta(days=1)
        edited_transaction.set_recurring(edited_transaction.return_byweekday())
    else:
        edited_transaction.count = form.count.data
        edited_transaction.until = form.until.data
        edited_transaction.title = form.title.data
        edited_transaction.date = form.date.data
        edited_transaction.description = form.description.data
        edited_transaction.income = form.income.data
        edited_transaction.is_recurring = form.is_recurring.data
        edited_transaction.freq = form.freq.data
        edited_transaction.interval = form.interval.data
        edited_transaction.set_amount(form.amount.data)
        if form.is_recurring.data:
            edited_transaction.set_recurring(form.byweekday.data)
    db.session.commit()