def add_transfer(): '''Add an account transfer''' current_user_id = session.get('logged_in_user') acc = Accounts(current_user_id) if request.method == 'POST': dict = __validate_transfer_form() for key in dict.keys(): exec(key + " = dict['" + key + "']") # 'heavier' checks if not error: # source and target the same? if not deduct_from_account == credit_to_account: # valid amount? if is_float(amount): # is it a positive amount? if float(amount) > 0: # valid date? if is_date(date): # valid debit account? if acc.is_account(account_id=deduct_from_account): # valid credit account? if acc.is_account( account_id=credit_to_account): # add a new transfer row acc.add_account_transfer( date=date, deduct_from_account=deduct_from_account, credit_to_account=credit_to_account, amount=amount) # modify accounts acc.modify_account_balance( deduct_from_account, -float(amount)) acc.modify_account_balance( credit_to_account, amount) flash('Monies transferred') else: error = 'Not a valid target account' else: error = 'Not a valid source account' else: error = 'Not a valid date' else: error = 'Provide a positive amount' else: error = 'Not a valid amount' else: error = 'Source and target accounts cannot be the same' accounts = acc.get_accounts() return render_template('admin_add_transfer.html', **locals())
def add_transfer(): """Add an account transfer""" current_user_id = session.get("logged_in_user") acc = Accounts(current_user_id) if request.method == "POST": dict = __validate_transfer_form() for key in dict.keys(): exec(key + " = dict['" + key + "']") # 'heavier' checks if not error: # source and target the same? if not deduct_from_account == credit_to_account: # valid amount? if is_float(amount): # is it a positive amount? if float(amount) > 0: # valid date? if is_date(date): # valid debit account? if acc.is_account(account_id=deduct_from_account): # valid credit account? if acc.is_account(account_id=credit_to_account): # add a new transfer row acc.add_account_transfer( date=date, deduct_from_account=deduct_from_account, credit_to_account=credit_to_account, amount=amount, ) # modify accounts acc.modify_account_balance(deduct_from_account, -float(amount)) acc.modify_account_balance(credit_to_account, amount) flash("Monies transferred") else: error = "Not a valid target account" else: error = "Not a valid source account" else: error = "Not a valid date" else: error = "Provide a positive amount" else: error = "Not a valid amount" else: error = "Source and target accounts cannot be the same" accounts = acc.get_accounts() return render_template("admin_add_transfer.html", **locals())
def edit_income(income_id): '''Edit income entry''' current_user_id = session.get('logged_in_user') inc = Income(current_user_id) # is it valid? income = inc.get_income(income_id) if income: # fetch user's categories and accounts categories = inc.get_categories() acc = Accounts(current_user_id) accounts = acc.get_accounts() if request.method == 'POST': # POST dict = __validate_income_form() for key in dict.keys(): exec(key + " = dict['" + key + "']") # 'heavier' checks if not error: # valid date? if is_date(date): # valid amount? if is_float(amount): # valid category? if inc.is_category(id=category_id): # valid account? if acc.is_account(account_id=account_id): # debit the original account acc.modify_account_balance(income.credit_to, -float(income.amount)) # credit the 'new' account acc.modify_account_balance(account_id, amount) # edit income entry inc.edit_income(account_id=account_id, amount=amount, category_id=category_id, date=date, description=description, income_id=income.id) flash('Income edited') return redirect(url_for('income.edit_income', income_id=income_id)) else: error = 'Not a valid account' else: error = 'Not a valid category' else: error = 'Not a valid amount' else: error = 'Not a valid date' return render_template('admin_edit_income.html', **locals()) else: return redirect(url_for('income.index'))
def add_income(): '''Add an income entry''' current_user_id = session.get('logged_in_user') inc = Income(current_user_id) acc = Accounts(current_user_id) if request.method == 'POST': dict = __validate_income_form() for key in dict.keys(): exec(key + " = dict['" + key + "']") # 'heavier' checks if not error: # valid date? if is_date(date): # valid amount? if is_float(amount): # valid category? if inc.is_category(id=category_id): # valid account? if acc.is_account(account_id=account_id): # add new income inc.add_income(account_id=account_id, amount=amount, category_id=category_id, date=date, description=description) # credit to account acc.modify_account_balance(account_id, amount) flash('Income added') else: error = 'Not a valid account' else: error = 'Not a valid category' else: error = 'Not a valid amount' else: error = 'Not a valid date' # fetch user's categories and accounts categories = inc.get_categories() accounts = acc.get_accounts() return render_template('admin_add_income.html', **locals())
def edit_transfer(transfer_id): '''Edit account transfer''' current_user_id = session.get('logged_in_user') acc = Accounts(current_user_id) accounts = acc.get_accounts() # is it valid? transfer = acc.get_transfer(transfer_id) if transfer: if request.method == 'POST': # POST dict = __validate_transfer_form() for key in dict.keys(): exec(key + " = dict['" + key + "']") # 'heavier' checks if not error: # source and target the same? if not deduct_from_account == credit_to_account: # valid amount? if is_float(amount): # valid date? if is_date(date): # valid debit account? if acc.is_account(account_id=deduct_from_account): # valid credit account? if acc.is_account(account_id=credit_to_account): # modify accounts to original state acc.modify_account_balance(transfer.from_account, transfer.amount) acc.modify_account_balance(transfer.to_account, -float(transfer.amount)) # new state acc.modify_account_balance(deduct_from_account, -float(amount)) acc.modify_account_balance(credit_to_account, amount) # edit transfer row transfer = acc.edit_account_transfer(date=date, deduct_from_account=deduct_from_account, credit_to_account=credit_to_account, amount=amount, transfer_id=transfer_id) flash('Transfer edited') else: error = 'Not a valid target account' else: error = 'Not a valid source account' else: error = 'Not a valid date' else: error = 'Not a valid amount' else: error = 'Source and target accounts cannot be the same' return render_template('admin_edit_transfer.html', **locals()) else: return redirect(url_for('accounts.show_transfers'))
def delete_transfer(transfer_id): """Delete account transfer""" current_user_id = session.get("logged_in_user") accounts = Accounts(current_user_id) # is it valid? transfer = accounts.get_transfer(transfer_id) if transfer: # revert accounts.modify_account_balance(transfer.from_account, transfer.amount) accounts.modify_account_balance(transfer.to_account, -float(transfer.amount)) accounts.delete_transfer(transfer_id) flash("Transfer deleted") else: flash("Not a valid account transfer", "error") return redirect(url_for("accounts.show_transfers"))
def delete_transfer(transfer_id): '''Delete account transfer''' current_user_id = session.get('logged_in_user') accounts = Accounts(current_user_id) # is it valid? transfer = accounts.get_transfer(transfer_id) if transfer: # revert accounts.modify_account_balance(transfer.from_account, transfer.amount) accounts.modify_account_balance(transfer.to_account, -float(transfer.amount)) accounts.delete_transfer(transfer_id) flash('Transfer deleted') else: flash('Not a valid account transfer', 'error') return redirect(url_for('accounts.show_transfers'))
def delete_income(income_id): '''Delete income entry''' current_user_id = session.get('logged_in_user') incomes = Income(current_user_id) # is it valid? income = incomes.get_income(income_id) if income: # revert accounts = Accounts(current_user_id) accounts.modify_account_balance(amount=-float(income.amount), account_id=income.credit_to) incomes.delete_income(income_id) flash('Income deleted') else: flash('Not a valid income entry', 'error') return redirect(url_for('income.index'))
def edit_income(income_id): '''Edit income entry''' current_user_id = session.get('logged_in_user') inc = Income(current_user_id) # is it valid? income = inc.get_income(income_id) if income: # fetch user's categories and accounts categories = inc.get_categories() acc = Accounts(current_user_id) accounts = acc.get_accounts() if request.method == 'POST': # POST dict = __validate_income_form() for key in dict.keys(): exec(key + " = dict['" + key + "']") # 'heavier' checks if not error: # valid date? if is_date(date): # valid amount? if is_float(amount): # valid category? if inc.is_category(id=category_id): # valid account? if acc.is_account(account_id=account_id): # debit the original account acc.modify_account_balance( income.credit_to, -float(income.amount)) # credit the 'new' account acc.modify_account_balance(account_id, amount) # edit income entry inc.edit_income(account_id=account_id, amount=amount, category_id=category_id, date=date, description=description, income_id=income.id) flash('Income edited') return redirect( url_for('income.edit_income', income_id=income_id)) else: error = 'Not a valid account' else: error = 'Not a valid category' else: error = 'Not a valid amount' else: error = 'Not a valid date' return render_template('admin_edit_income.html', **locals()) else: return redirect(url_for('income.index'))
def edit_transfer(transfer_id): '''Edit account transfer''' current_user_id = session.get('logged_in_user') acc = Accounts(current_user_id) accounts = acc.get_accounts() # is it valid? transfer = acc.get_transfer(transfer_id) if transfer: if request.method == 'POST': # POST dict = __validate_transfer_form() for key in dict.keys(): exec(key + " = dict['" + key + "']") # 'heavier' checks if not error: # source and target the same? if not deduct_from_account == credit_to_account: # valid amount? if is_float(amount): # valid date? if is_date(date): # valid debit account? if acc.is_account(account_id=deduct_from_account): # valid credit account? if acc.is_account( account_id=credit_to_account): # modify accounts to original state acc.modify_account_balance( transfer.from_account, transfer.amount) acc.modify_account_balance( transfer.to_account, -float(transfer.amount)) # new state acc.modify_account_balance( deduct_from_account, -float(amount)) acc.modify_account_balance( credit_to_account, amount) # edit transfer row transfer = acc.edit_account_transfer( date=date, deduct_from_account=deduct_from_account, credit_to_account=credit_to_account, amount=amount, transfer_id=transfer_id) flash('Transfer edited') else: error = 'Not a valid target account' else: error = 'Not a valid source account' else: error = 'Not a valid date' else: error = 'Not a valid amount' else: error = 'Source and target accounts cannot be the same' return render_template('admin_edit_transfer.html', **locals()) else: return redirect(url_for('accounts.show_transfers'))