05/31 Phase 7: fixed fetch fx rate
This commit is contained in:
+16
-1
@@ -5,7 +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.services.fx_service import get_today_rate, get_rate_history
|
||||
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
|
||||
from datetime import date, datetime, timedelta
|
||||
@@ -161,3 +161,18 @@ def fx_history_api():
|
||||
'dates': [r.date.strftime('%b %d') for r in history],
|
||||
'rates': [float(r.usd_to_vnd) for r in history],
|
||||
})
|
||||
|
||||
|
||||
@dashboard_bp.route('/api/fx-refresh', methods=['POST'])
|
||||
@login_required
|
||||
def fx_refresh():
|
||||
"""Force-refresh today's USD/VND rate."""
|
||||
result = force_refresh()
|
||||
if result:
|
||||
return jsonify({
|
||||
'rate': result['rate'],
|
||||
'date': result['date'].strftime('%b %d, %Y'),
|
||||
'source': result['source'],
|
||||
'is_stale': result['is_stale'],
|
||||
})
|
||||
return jsonify({'error': 'Could not fetch rate'}), 503
|
||||
|
||||
Reference in New Issue
Block a user