06/02 Optimize app 2
This commit is contained in:
@@ -217,3 +217,28 @@ def manual_snapshot():
|
||||
snap = take_net_worth_snapshot()
|
||||
flash(f'Net worth snapshot saved: {snap.snapshot_date.strftime("%B %d, %Y")}', 'success')
|
||||
return redirect(url_for('reports.index'))
|
||||
|
||||
|
||||
@reports_bp.route('/rebuild-snapshot', methods=['POST'])
|
||||
@login_required
|
||||
def rebuild_snapshot():
|
||||
"""Recalculate all balances then replace today's snapshot with fresh data."""
|
||||
from app.services.account_service import recalc_all
|
||||
from app.models.net_worth_snapshot import NetWorthSnapshot
|
||||
|
||||
recalc_all()
|
||||
|
||||
# Delete today's snapshot so take_net_worth_snapshot() creates a fresh one
|
||||
today = date.today()
|
||||
existing = NetWorthSnapshot.query.filter_by(snapshot_date=today).first()
|
||||
if existing:
|
||||
from app.extensions import db
|
||||
db.session.delete(existing)
|
||||
db.session.commit()
|
||||
|
||||
snap = take_net_worth_snapshot()
|
||||
flash(
|
||||
f'Balances recalculated and snapshot rebuilt for {snap.snapshot_date.strftime("%B %d, %Y")}.',
|
||||
'success'
|
||||
)
|
||||
return redirect(url_for('reports.index'))
|
||||
|
||||
Reference in New Issue
Block a user