Ejemplo n.º 1
0
def plot(account_name):
    if check_account_existence(account_name) is False:
        return render_template('account_not_found.html', account_name=account_name)
    plot_list = BankAccount.query.filter_by(account_name=account_name).first().operations.all()
    line_chart = pygal.Line()
    line_chart.title = 'Incomes/Costs plot'
    line_chart.x_label = map(str, range(1, len(plot_list) + 1))
    line_chart.add('Trend line', list(map(lambda op: op.account_amount_before_operation, plot_list)))
    return line_chart.render_response()
Ejemplo n.º 2
0
def delete(account_name):
    if check_account_existence(account_name) is False:
        return render_template('account_not_found.html', account_name=account_name)
    account = BankAccount.query.filter_by(account_name=account_name).first()
    for transaction in account.transactions.all():
        db.session.delete(transaction)
    for saving_account in account.saving_accounts.all():
        db.session.delete(saving_account)
    db.session.delete(account)
    db.session.commit()
    return redirect(url_for('profile'))
Ejemplo n.º 3
0
def operations(account_name):
    if check_account_existence(account_name) is False:
        return render_template('account_not_found.html', account_name=account_name)
    account = BankAccount.query.filter_by(account_name=account_name).first()
    form = SearchForm()
    if form.validate_on_submit():
        type = form.type.data
        category = 'Default' if form.category.data == '' else form.category.data
        return render_template('search_result_list.html', type=type, category=category,
                               list=search_function(is_operations=True, account_name=account_name, type=type,
                                                    category=category), account=account)
    return render_template('search_page.html', form=form, account=account)
Ejemplo n.º 4
0
def transfer(account_name):
    if check_account_existence(account_name) is False:
        return render_template('account_not_found.html', account_name=account_name)
    account = BankAccount.query.filter_by(account_name=account_name).first()
    transfer_form = TransferForm()
    if transfer_form.validate_on_submit():
        try:
            recipient_account = BankAccount.query.filter_by(account_name=transfer_form.recipient.data).first()
            do_transaction(sender=account, recipient=recipient_account, amount=float(transfer_form.transfer_amount.data),
                           category='Default' if transfer_form.category.data == '' else transfer_form.category.data)
            redirect(url_for('profile'))
        except NotEnoughMoneyException:
            return render_template('not_enough_money.html', err_info='to do transaction', account=account)
    return render_template('transfer_page.html', account=account, form=transfer_form)
Ejemplo n.º 5
0
def bank_account(account_name):
    if check_account_existence(account_name) is False:
        return render_template('account_not_found.html', account_name=account_name)
    account = BankAccount.query.filter_by(account_name=account_name).first()
    operation_form = OperationForm()
    if operation_form.validate_on_submit():
        try:
            do_operation(account, is_income=True if operation_form.operation_type.data == 'Income' else False,
                         amount=float(operation_form.operation_amount.data),
                         category='Default' if operation_form.category.data == '' else operation_form.category.data)
            redirect(url_for('profile'))
        except NotEnoughMoneyException:
            return render_template('not_enough_money.html', err_info='to do operation', account=account)

    return render_template('account_view.html', account=account, form=operation_form)
Ejemplo n.º 6
0
def new_saving_account(account_name):
    if check_account_existence(account_name) is False:
        return render_template('account_not_found.html', account_name=account_name)
    account = BankAccount.query.filter_by(account_name=account_name).first()
    form = SavingAccountForm()
    if form.validate_on_submit():
        if account.cash_amount < float(form.account_amount.data):
            return render_template('not_enough_money.html', err_info='to create saving account', account=account)
        account.cash_amount -= float(form.account_amount.data)
        saving_account = SavingAccount(account_name=form.name.data, account_amount=int(form.account_amount.data),
                                       account_currency=get_currency_sign(account.account_currency),
                                       parent_account=account)
        db.session.add(saving_account)
        db.session.commit()
        return redirect(url_for('saving_accounts', account_name=account.account_name))
    return render_template('new_saving_account.html', form=form, account=account)
Ejemplo n.º 7
0
def saving_accounts(account_name):
    if check_account_existence(account_name) is False:
        return render_template('account_not_found.html', account_name=account_name)
    account = BankAccount.query.filter_by(account_name=account_name).first()
    saving_accounts = account.saving_accounts.all()
    return render_template('saving_accounts.html', account=account, saving_accounts=saving_accounts)