06/05 Optimize app

This commit is contained in:
2026-06-05 15:51:57 -04:00
parent 458044201e
commit 025f3f8823
14 changed files with 425 additions and 64 deletions
+12 -1
View File
@@ -5,6 +5,7 @@ from app.extensions import db
from app.models.account import Account
from app.models.transaction import Transaction
from app.models.category import Category
from app.models.recurring_rule import RecurringRule
from app.services.fx_service import get_today_rate, get_rate_history, force_refresh
from app.services.ai_service import get_latest_daily_insight
from app.services.account_service import get_total_assets, get_total_liabilities
@@ -145,6 +146,14 @@ def index():
chart_income.append(float(inc))
chart_expense.append(float(exp))
# ── Upcoming bills (recurring rules due within 14 days) ──────────────────
upcoming_bills = RecurringRule.query.filter(
RecurringRule.is_active == True,
RecurringRule.next_run != None,
RecurringRule.next_run >= today,
RecurringRule.next_run <= today + timedelta(days=14),
).order_by(RecurringRule.next_run).limit(8).all()
# ── Recent transactions ───────────────────────────
recent_txns = Transaction.query\
.filter(Transaction.transaction_type.in_(['income', 'expense']))\
@@ -185,7 +194,9 @@ def index():
fx=fx,
fx_history_data=fx_history_data,
ai_insight=ai_insight,
schwab_warning=schwab_warning)
schwab_warning=schwab_warning,
upcoming_bills=upcoming_bills,
today=today)
@dashboard_bp.route('/api/reconcile')
+8
View File
@@ -8,6 +8,7 @@ from app.models.investment import Investment, InvestmentTransaction
from app.services.investment_service import (
get_portfolio_summary, update_prices, fetch_price,
fetch_price_history, fetch_day_change,
get_price_alerts,
ASSET_COLORS, ASSET_TYPE_LABELS
)
from datetime import date
@@ -341,6 +342,13 @@ def api_day_change(ticker):
return jsonify(data)
@investments_bp.route('/api/price-alerts')
@login_required
def api_price_alerts():
"""Return today's price-alert list (holdings that moved >= 5% intraday)."""
return jsonify({'alerts': get_price_alerts()})
@investments_bp.route('/api/history/<ticker>')
@login_required
def api_price_history(ticker):
+6 -7
View File
@@ -1,5 +1,5 @@
from flask import (Blueprint, render_template, request, redirect, url_for,
Response, flash, send_file)
Response, flash, send_file, stream_with_context)
from flask_login import login_required, current_user
from app.models.transaction import Transaction
from app.services.report_service import (
@@ -8,7 +8,7 @@ from app.services.report_service import (
take_net_worth_snapshot, category_mom_comparison,
)
from app.services.export_service import (
transactions_to_csv, transactions_to_excel,
transactions_csv_stream, transactions_to_excel,
report_to_pdf, build_report_html,
)
from datetime import date
@@ -141,14 +141,13 @@ def export_csv():
)
if txn_type != 'all':
query = query.filter(Transaction.transaction_type == txn_type)
transactions = query.order_by(Transaction.date.desc()).all()
query = query.order_by(Transaction.date.desc())
csv_data = transactions_to_csv(transactions)
label = f'{year}-{month:02d}' if month else str(year)
filename = f'pfm_transactions_{label}.csv'
return Response(
csv_data,
stream_with_context(transactions_csv_stream(query)),
mimetype='text/csv',
headers={'Content-Disposition': f'attachment; filename="{filename}"'}
)
@@ -167,11 +166,11 @@ def export_excel():
__import__('calendar').monthrange(year, month)[1]),
Transaction.transaction_type.in_(['income', 'expense']),
)
transactions = query.order_by(Transaction.date.desc()).all()
query = query.order_by(Transaction.date.desc())
label = f'{year}-{month:02d}' if month else str(year)
period_label = f'{year} Month {month}' if month else str(year)
excel_bytes = transactions_to_excel(transactions, period_label)
excel_bytes = transactions_to_excel(query, period_label)
filename = f'pfm_transactions_{label}.xlsx'
return send_file(