Adds fiat currency support for expenses
Extends expense entry functionality to support fiat currencies. Users can now specify a currency (e.g., EUR, USD) when creating expense entries. The specified amount is converted to satoshis using exchange rates. The converted amount and currency information are stored in the journal entry metadata. Also adds an API endpoint to retrieve allowed currencies and updates the UI to allow currency selection when creating expense entries.
This commit is contained in:
parent
4bd83d6937
commit
cd083114b4
5 changed files with 97 additions and 10 deletions
11
models.py
11
models.py
|
|
@ -36,6 +36,7 @@ class EntryLine(BaseModel):
|
|||
debit: int = 0 # in satoshis
|
||||
credit: int = 0 # in satoshis
|
||||
description: Optional[str] = None
|
||||
metadata: dict = {} # Stores currency info: fiat_currency, fiat_amount, fiat_rate, etc.
|
||||
|
||||
|
||||
class CreateEntryLine(BaseModel):
|
||||
|
|
@ -43,6 +44,7 @@ class CreateEntryLine(BaseModel):
|
|||
debit: int = 0
|
||||
credit: int = 0
|
||||
description: Optional[str] = None
|
||||
metadata: dict = {} # Stores currency info
|
||||
|
||||
|
||||
class JournalEntry(BaseModel):
|
||||
|
|
@ -72,28 +74,31 @@ class ExpenseEntry(BaseModel):
|
|||
"""Helper model for creating expense entries"""
|
||||
|
||||
description: str
|
||||
amount: int # in satoshis
|
||||
amount: float # Amount in the specified currency (or satoshis if currency is None)
|
||||
expense_account: str # account name or ID
|
||||
is_equity: bool = False # True = equity contribution, False = liability (castle owes user)
|
||||
user_wallet: str
|
||||
reference: Optional[str] = None
|
||||
currency: Optional[str] = None # If None, amount is in satoshis. Otherwise, fiat currency code (EUR, USD, etc.)
|
||||
|
||||
|
||||
class ReceivableEntry(BaseModel):
|
||||
"""Helper model for creating accounts receivable entries"""
|
||||
|
||||
description: str
|
||||
amount: int # in satoshis
|
||||
amount: float # Amount in the specified currency (or satoshis if currency is None)
|
||||
revenue_account: str # account name or ID
|
||||
user_wallet: str
|
||||
reference: Optional[str] = None
|
||||
currency: Optional[str] = None # If None, amount is in satoshis. Otherwise, fiat currency code
|
||||
|
||||
|
||||
class RevenueEntry(BaseModel):
|
||||
"""Helper model for creating revenue entries"""
|
||||
|
||||
description: str
|
||||
amount: int # in satoshis
|
||||
amount: float # Amount in the specified currency (or satoshis if currency is None)
|
||||
revenue_account: str
|
||||
payment_method_account: str # e.g., "Cash", "Bank", "Lightning"
|
||||
reference: Optional[str] = None
|
||||
currency: Optional[str] = None # If None, amount is in satoshis. Otherwise, fiat currency code
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue