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.

This commit is contained in:
padreug 2025-07-05 14:59:05 +02:00
parent f32e1bb9ae
commit d2866276a9
3 changed files with 13 additions and 11 deletions

View file

@ -11,11 +11,11 @@ class ClientDashboardSummary(BaseModel):
"""Summary metrics for client dashboard overview""" """Summary metrics for client dashboard overview"""
user_id: str user_id: str
total_sats_accumulated: int total_sats_accumulated: int
total_fiat_invested: int # Confirmed deposits total_fiat_invested: int # Confirmed deposits (in centavos)
pending_fiat_deposits: int # Pending deposits awaiting confirmation pending_fiat_deposits: int # Pending deposits awaiting confirmation (in centavos)
current_sats_fiat_value: float # Current fiat value of total sats current_sats_fiat_value: float # Current fiat value of total sats (in centavos)
average_cost_basis: float # Average sats per fiat unit 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 total_transactions: int
dca_mode: str # 'flow' or 'fixed' dca_mode: str # 'flow' or 'fixed'
dca_status: str # 'active' or 'inactive' dca_status: str # 'active' or 'inactive'
@ -27,7 +27,7 @@ class ClientTransaction(BaseModel):
"""Read-only view of client's DCA transactions""" """Read-only view of client's DCA transactions"""
id: str id: str
amount_sats: int amount_sats: int
amount_fiat: int amount_fiat: int # Stored in centavos (GTQ * 100) for precision
exchange_rate: float exchange_rate: float
transaction_type: str # 'flow', 'fixed', 'manual' transaction_type: str # 'flow', 'fixed', 'manual'
status: str status: str

View file

@ -183,24 +183,26 @@ window.app = Vue.createApp({
// Dashboard Methods // Dashboard Methods
formatCurrency(amount) { formatCurrency(amount) {
if (!amount) return 'Q 0.00'; 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', { return new Intl.NumberFormat('es-GT', {
style: 'currency', style: 'currency',
currency: 'GTQ', currency: 'GTQ',
}).format(amount); }).format(gtqAmount);
}, },
formatCurrencyWithCode(amount, currencyCode) { formatCurrencyWithCode(amount, currencyCode) {
if (!amount) return `${currencyCode} 0.00`; 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 { try {
return new Intl.NumberFormat('en-US', { return new Intl.NumberFormat('en-US', {
style: 'currency', style: 'currency',
currency: currencyCode, currency: currencyCode,
}).format(amount); }).format(currencyAmount);
} catch (error) { } catch (error) {
// Fallback if currency code is not supported // Fallback if currency code is not supported
return `${currencyCode} ${amount.toFixed(2)}`; return `${currencyCode} ${currencyAmount.toFixed(2)}`;
} }
}, },

View file

@ -199,7 +199,7 @@ async def api_export_transactions(
writer.writerow([ writer.writerow([
tx.created_at.isoformat(), tx.created_at.isoformat(),
tx.amount_sats, 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.exchange_rate,
tx.transaction_type, tx.transaction_type,
tx.status tx.status