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:
parent
f32e1bb9ae
commit
d2866276a9
3 changed files with 13 additions and 11 deletions
10
models.py
10
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
|
||||
|
|
|
|||
|
|
@ -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)}`;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue