Example #1
0
def transaction(transaction_id):
    form = TransactionForm()
    form.category.choices = categoriesSelectBox()

    q = db.session.query(Transaction).filter(
        Transaction.id == transaction_id).first()
    if form.validate_on_submit():
        q.bdate = form.bdate.data
        q.name = form.name.data
        q.category_id = form.category.data
        q.amount = form.amount.data
        q.yearly = form.yearly.data

        db.session.commit()

        return redirect(url_for('transactions', category_id=q.category_id))

    else:
        form.tdate.data = q.tdate
        form.bdate.data = q.bdate
        form.name.data = q.name
        form.category.data = q.category_id
        form.amount.data = q.amount
        form.yearly.data = q.yearly

    return render_template('transaction.html',
                           form=form,
                           transaction_id=transaction_id,
                           title='Transaction')
Example #2
0
    def test_select_box(self):
        expected = [
            (1, 'top'),
            (2, '...child'),
            (3, '......grandchild'),
            (4, '...uncategorized'),
        ]

        assert_equals(categoriesSelectBox(), expected)
Example #3
0
def split_transaction(transaction_id):
    q = db.session.query(Transaction).filter(
        Transaction.id == transaction_id).first()

    form = SplitTransactionForm()
    form.category_1.choices = categoriesSelectBox()
    form.category_2.choices = categoriesSelectBox()

    if form.validate_on_submit():
        q.bdate = form.bdate_1.data
        q.name = form.name_1.data
        q.category_id = form.category_1.data
        q.amount = form.amount_1.data
        q.yearly = form.yearly_1.data

        db.session.add(
            Transaction(q.tdate, form.name_2.data, form.category_2.data,
                        form.amount_2.data, q.trans_file, form.bdate_2.data,
                        form.yearly_2.data))

        db.session.commit()

        return redirect(url_for('transactions', category_id=q.category_id))

    else:
        form.bdate_1.data = q.bdate
        form.name_1.data = q.name
        form.category_1.data = q.category_id
        form.amount_1.data = q.amount
        form.yearly_1.data = q.yearly

        form.bdate_2.data = q.bdate

    return render_template('split_transaction.html',
                           form=form,
                           title='Split Transaction')
Example #4
0
def transactions(category_id=None, name=None):
    form = TransactionsForm()
    form.category.choices = categoriesSelectBox()

    if form.validate_on_submit():
        category_id = form.category.data
        session['startdate'] = str(form.startdate.data)
        session['enddate'] = str(form.enddate.data)
    elif category_id:
        form.category.data = category_id

    if 'startdate' in session:
        form.startdate.data = datetime.date(
            *map(int, session['startdate'].split('-')))
    if 'enddate' in session:
        form.enddate.data = datetime.date(
            *map(int, session['enddate'].split('-')))

    q = db.session.query(Transaction)
    if form.category.data:
        c = db.session.query(Category).filter(
            Category.id == form.category.data).first()
        children = [c] + allChildren(c)
        q = q.join(Category).filter(
            Category.id.in_([child.id for child in children]))

    if name:
        name = unquote(name)
        q = q.filter(Transaction.name == name)

    q = q.filter(
        Transaction.bdate >= form.startdate.data,
        Transaction.bdate <= form.enddate.data,
    ).order_by(desc(Transaction.bdate))

    graph = collections.defaultdict(float)
    for tran in q:
        if not tran.yearly:
            graph[tran.bdate.replace(day=1)] += tran.amount

    return render_template(
        'transactions.html',
        form=form,
        transactions=[q],
        title='Transactions',
        graph=collections.OrderedDict([(k, abs(v))
                                       for k, v in sorted(graph.items())]),
    )
Example #5
0
def upload_transactions():
    return render_template('upload_transactions.html', categories=categoriesSelectBox())
Example #6
0
def transactions(category_id=None):
    return render_template(
        'transactions.html', 
        table=transaction.transactions(category_id),
        categories=categoriesSelectBox(),
    )