Beispiel #1
0
def edit_accounts(account_id):
    db_session = create_session()
    accounts_dao = AccountDAO(db_session)

    account = accounts_dao.find_by_id_and_user_id(account_id, session["id"])
    db_session.close()
    return render_template("accounts/edit.html", account=account)
Beispiel #2
0
def list_accounts():
    db_session = create_session()
    accounts_dao = AccountDAO(db_session)

    accounts = accounts_dao.find_by_user_id(session["id"])
    db_session.close()
    return render_template("accounts/index.html", accounts=accounts)
Beispiel #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
    )
Beispiel #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)
Beispiel #5
0
def validate_accounts(db_session, *account_ids, user_id):
    account_dao = AccountDAO(db_session)
    for account_id in account_ids:
        if account_id is None or int(account_id) == -1:
            continue

        print(f"Validating account '{account_id}'")
        account = account_dao.find_by_id_and_user_id(
            account_id=account_id,
            user_id=user_id
        )
        if account is None:
            return False
    return True
Beispiel #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
    )
Beispiel #7
0
def save_accounts():
    db_session = create_session()
    accounts_dao = AccountDAO(db_session)

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

    accounts_dao.save(
        account_id=account_id,
        name=request.form["name"],
        user_id=session["id"],
        account_type=request.form["type"],
    )

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