From d2866276a9722b8324907fed55220cbfbeb4e1ec Mon Sep 17 00:00:00 2001 From: padreug Date: Sat, 5 Jul 2025 14:59:05 +0200 Subject: [PATCH] Update currency handling in models and views: Modify model attributes to specify values in centavos for precision. Adjust CSV export and currency formatting functions to convert centavos to GTQ for accurate display and export. --- models.py | 10 +++++----- static/js/index.js | 12 +++++++----- views_api.py | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/models.py b/models.py index c0a436f..267d22f 100644 --- a/models.py +++ b/models.py @@ -11,11 +11,11 @@ class ClientDashboardSummary(BaseModel): """Summary metrics for client dashboard overview""" user_id: str total_sats_accumulated: int - total_fiat_invested: int # Confirmed deposits - pending_fiat_deposits: int # Pending deposits awaiting confirmation - current_sats_fiat_value: float # Current fiat value of total sats + total_fiat_invested: int # Confirmed deposits (in centavos) + pending_fiat_deposits: int # Pending deposits awaiting confirmation (in centavos) + current_sats_fiat_value: float # Current fiat value of total sats (in centavos) average_cost_basis: float # Average sats per fiat unit - current_fiat_balance: int # Available balance for DCA + current_fiat_balance: int # Available balance for DCA (in centavos) total_transactions: int dca_mode: str # 'flow' or 'fixed' dca_status: str # 'active' or 'inactive' @@ -27,7 +27,7 @@ class ClientTransaction(BaseModel): """Read-only view of client's DCA transactions""" id: str amount_sats: int - amount_fiat: int + amount_fiat: int # Stored in centavos (GTQ * 100) for precision exchange_rate: float transaction_type: str # 'flow', 'fixed', 'manual' status: str diff --git a/static/js/index.js b/static/js/index.js index 14a2c15..237c587 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -183,24 +183,26 @@ window.app = Vue.createApp({ // Dashboard Methods formatCurrency(amount) { if (!amount) return 'Q 0.00'; - // Values are already in full currency units, not centavos + // Convert centavos to GTQ (divide by 100) for display + const gtqAmount = amount / 100; return new Intl.NumberFormat('es-GT', { style: 'currency', currency: 'GTQ', - }).format(amount); + }).format(gtqAmount); }, formatCurrencyWithCode(amount, currencyCode) { if (!amount) return `${currencyCode} 0.00`; - // Format with the provided currency code + // Convert centavos to currency units (divide by 100) for display + const currencyAmount = amount / 100; try { return new Intl.NumberFormat('en-US', { style: 'currency', currency: currencyCode, - }).format(amount); + }).format(currencyAmount); } catch (error) { // Fallback if currency code is not supported - return `${currencyCode} ${amount.toFixed(2)}`; + return `${currencyCode} ${currencyAmount.toFixed(2)}`; } }, diff --git a/views_api.py b/views_api.py index 316e15e..fed1d27 100644 --- a/views_api.py +++ b/views_api.py @@ -199,7 +199,7 @@ async def api_export_transactions( writer.writerow([ tx.created_at.isoformat(), tx.amount_sats, - tx.amount_fiat, # Values are already in full currency units + tx.amount_fiat / 100, # Convert centavos to GTQ for CSV export tx.exchange_rate, tx.transaction_type, tx.status