06/02 Update functionalities
This commit is contained in:
+20
-1
@@ -1,10 +1,13 @@
|
||||
from datetime import date
|
||||
from flask import Blueprint, render_template, redirect, url_for, flash, request, jsonify
|
||||
from flask_login import login_required
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, SelectField, TextAreaField, SubmitField
|
||||
from wtforms.validators import DataRequired, Length, Optional
|
||||
from sqlalchemy import func, extract
|
||||
from app.extensions import db
|
||||
from app.models.account import Account
|
||||
from app.models.transaction import Transaction
|
||||
from app.services.account_service import calc_balance
|
||||
|
||||
accounts_bp = Blueprint('accounts', __name__, url_prefix='/accounts')
|
||||
@@ -63,11 +66,27 @@ def index():
|
||||
credit_accounts = [a for a in all_accounts if a.account_type == 'credit_card']
|
||||
accounts = credit_accounts if tab == 'credit' else bank_accounts
|
||||
|
||||
# Monthly charges per credit card (current month expenses)
|
||||
today = date.today()
|
||||
monthly_charges = {}
|
||||
if credit_accounts:
|
||||
rows = db.session.query(
|
||||
Transaction.account_id,
|
||||
func.sum(Transaction.amount)
|
||||
).filter(
|
||||
Transaction.transaction_type == 'expense',
|
||||
extract('year', Transaction.date) == today.year,
|
||||
extract('month', Transaction.date) == today.month,
|
||||
Transaction.account_id.in_([a.id for a in credit_accounts])
|
||||
).group_by(Transaction.account_id).all()
|
||||
monthly_charges = {row[0]: float(row[1]) for row in rows}
|
||||
|
||||
return render_template('accounts/index.html',
|
||||
accounts=accounts,
|
||||
tab=tab,
|
||||
bank_count=len(bank_accounts),
|
||||
credit_count=len(credit_accounts))
|
||||
credit_count=len(credit_accounts),
|
||||
monthly_charges=monthly_charges)
|
||||
|
||||
|
||||
@accounts_bp.route('/new', methods=['GET', 'POST'])
|
||||
|
||||
@@ -241,6 +241,14 @@ def transfer():
|
||||
form.from_account_id.choices = _account_choices()
|
||||
form.to_account_id.choices = _account_choices()
|
||||
|
||||
if request.method == 'GET':
|
||||
prefill_to = request.args.get('to_account_id', '')
|
||||
prefill_desc = request.args.get('description', '')
|
||||
if prefill_to:
|
||||
form.to_account_id.data = prefill_to
|
||||
if prefill_desc:
|
||||
form.description.data = prefill_desc
|
||||
|
||||
if form.validate_on_submit():
|
||||
if form.from_account_id.data == form.to_account_id.data:
|
||||
flash('Source and destination accounts must be different.', 'warning')
|
||||
|
||||
Reference in New Issue
Block a user