예제 #1
0
def edit_category(category_id):
    db_session = create_session()
    categories_dao = CategoryDAO(db_session)

    category = categories_dao.find_by_id_and_user_id(category_id, session["id"])
    db_session.close()
    return render_template("categories/edit.html", category=category)
예제 #2
0
def list_categories():
    db_session = create_session()
    categories_dao = CategoryDAO(db_session)

    categories = categories_dao.find_by_user_id(session["id"])
    db_session.close()
    return render_template("categories/index.html", categories=categories)
예제 #3
0
def edit_transaction(transaction_id):
    db_session = create_session()
    category_dao = CategoryDAO(db_session)
    categories = category_dao.find_by_user_id(session["id"])
    account_dao = AccountDAO(db_session)
    accounts = account_dao.find_by_user_id(session["id"])
    transaction_dao = TransactionDAO(db_session)
    transaction = transaction_dao.find_by_id_and_user_id(
        transaction_id=transaction_id,
        user_id=session["id"]
    )
    destination_accnt_id = None
    linked_transaction_id = None
    if transaction.link_id is not None:
        linked_transaction = transaction_dao.find_linked_transaction(
            link_id=transaction.link_id,
            user_id=session["id"],
            transaction_id=transaction.id
        )
        destination_accnt_id = linked_transaction.source_accnt_id
        linked_transaction_id = linked_transaction.id
    db_session.close()
    return render_template(
        "transactions/edit.html",
        categories=categories,
        accounts=accounts,
        category_id=transaction.category_id,
        date=transaction.date,
        description=transaction.description,
        destination_accnt_id=destination_accnt_id,
        id=transaction.id,
        source_accnt_id=transaction.source_accnt_id,
        value=transaction.value,
        link_id=linked_transaction_id
    )
예제 #4
0
def list_transactions():
    db_session = create_session()
    transaction_dao = TransactionDAO(db_session)
    all_transactions = transaction_dao.find_by_user_id(user_id=session["id"])
    category_dao = CategoryDAO(db_session)
    categories = category_dao.find_by_user_id(session["id"])
    account_dao = AccountDAO(db_session)
    accounts = account_dao.find_by_user_id(session["id"])
    db_session.close()
    return render_template("transactions/index.html",
                           transactions=all_transactions,
                           categories=categories,
                           accounts=accounts)
예제 #5
0
def validate_categories(db_session, *category_ids, user_id):
    category_dao = CategoryDAO(db_session)
    for category_id in category_ids:
        if category_id is None or int(category_id) == -1:
            continue

        category = category_dao.find_by_id_and_user_id(
            category_id=category_id,
            user_id=user_id
        )
        if category is None:
            return False
    return True
예제 #6
0
def new_transaction():
    db_session = create_session()
    category_dao = CategoryDAO(db_session)
    categories = category_dao.find_by_user_id(session["id"])
    account_dao = AccountDAO(db_session)
    accounts = account_dao.find_by_user_id(session["id"])
    db_session.close()
    return render_template(
        "transactions/edit.html",
        categories=categories,
        date=datetime.now(),
        destination_accnt_id=None,
        accounts=accounts
    )
예제 #7
0
def save_category():
    db_session = create_session()
    categories_dao = CategoryDAO(db_session)

    category_id = request.form["id"]
    if category_id == "":
        category_id = None

    categories_dao.save(
        category_id=category_id,
        name=request.form["name"],
        user_id=session["id"],
    )

    db_session.commit()
    db_session.close()
    return redirect(url_for("list_categories"))