06/02 Update functionalities

This commit is contained in:
2026-06-02 15:28:31 -04:00
parent c429de7bcd
commit 814ec90581
3 changed files with 62 additions and 7 deletions
+20 -1
View File
@@ -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'])