Enhances Beancount import and API entry creation
Improves the Beancount import process to send SATS amounts with fiat metadata to the API, enabling automatic conversion to EUR-based postings. Updates the API to store entries in Fava instead of the Castle DB, simplifying the JournalEntry creation process. Adds error handling to the upload entry function. Includes a note about imported transactions being stored in EUR with SATS in metadata.
This commit is contained in:
parent
1d605be021
commit
0e93fc5ffc
2 changed files with 41 additions and 50 deletions
46
views_api.py
46
views_api.py
|
|
@ -654,8 +654,8 @@ async def api_create_journal_entry(
|
|||
result = await fava.add_entry(entry)
|
||||
logger.info(f"Journal entry submitted to Fava: {result.get('data', 'Unknown')}")
|
||||
|
||||
# Return mock JournalEntry for API compatibility
|
||||
# TODO: Query Fava to get the actual entry back with its hash
|
||||
# Return simplified JournalEntry for API compatibility
|
||||
# Note: Castle no longer stores entries in DB, Fava is the source of truth
|
||||
timestamp = datetime.now().timestamp()
|
||||
return JournalEntry(
|
||||
id=f"fava-{timestamp}",
|
||||
|
|
@ -665,18 +665,8 @@ async def api_create_journal_entry(
|
|||
created_at=datetime.now(),
|
||||
reference=data.reference,
|
||||
flag=data.flag if data.flag else JournalEntryFlag.CLEARED,
|
||||
lines=[
|
||||
EntryLine(
|
||||
id=f"fava-{timestamp}-{i}",
|
||||
journal_entry_id=f"fava-{timestamp}",
|
||||
account_id=line.account_id,
|
||||
amount=line.amount,
|
||||
description=line.description,
|
||||
metadata=line.metadata
|
||||
)
|
||||
for i, line in enumerate(data.lines)
|
||||
],
|
||||
meta={**data.meta, "source": "fava", "fava_response": result.get('data', 'Unknown')}
|
||||
lines=[], # Empty - entry is stored in Fava, not Castle DB
|
||||
meta={"source": "fava", "fava_response": result.get('data', 'Unknown')}
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -1068,33 +1058,17 @@ async def api_create_revenue_entry(
|
|||
result = await fava.add_entry(entry)
|
||||
logger.info(f"Revenue entry submitted to Fava: {result.get('data', 'Unknown')}")
|
||||
|
||||
# Return JournalEntry for API compatibility
|
||||
# Return simplified JournalEntry for API compatibility
|
||||
# Note: Castle no longer stores entries in DB, Fava is the source of truth
|
||||
return JournalEntry(
|
||||
id=entry_id, # Use the generated castle entry ID
|
||||
id=entry_id,
|
||||
description=data.description,
|
||||
entry_date=datetime.now(),
|
||||
created_by=wallet.wallet.id,
|
||||
created_at=datetime.now(),
|
||||
reference=castle_reference, # Use castle reference with unique ID
|
||||
flag=JournalEntryFlag.CLEARED, # Revenue entries are cleared
|
||||
lines=[
|
||||
EntryLine(
|
||||
id=f"line-1-{entry_id}",
|
||||
journal_entry_id=entry_id,
|
||||
account_id=payment_account.id,
|
||||
amount=amount_sats,
|
||||
description="Payment received",
|
||||
metadata={"fiat_currency": fiat_currency, "fiat_amount": str(fiat_amount)} if fiat_currency else {}
|
||||
),
|
||||
EntryLine(
|
||||
id=f"line-2-{entry_id}",
|
||||
journal_entry_id=entry_id,
|
||||
account_id=revenue_account.id,
|
||||
amount=-amount_sats,
|
||||
description="Revenue earned",
|
||||
metadata={}
|
||||
)
|
||||
],
|
||||
reference=castle_reference,
|
||||
flag=JournalEntryFlag.CLEARED,
|
||||
lines=[], # Empty - entry is stored in Fava, not Castle DB
|
||||
meta={"source": "fava", "fava_response": result.get('data', 'Unknown')}
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue