diff --git a/beancount_format.py b/beancount_format.py index b895124..6b8d196 100644 --- a/beancount_format.py +++ b/beancount_format.py @@ -112,13 +112,9 @@ def format_posting_with_cost( # Returns: { # "account": "Expenses:Food", # "amount": "200000 SATS {100.00 EUR}", - # "meta": { - # "fiat-currency": "EUR", - # "fiat-amount": "100.00", - # "sats-equivalent": "200000", - # "exchange-rate": "2000.00" - # } + # "meta": {} # } + # Note: All fiat/exchange rate info is in the cost syntax "{100.00 EUR}" """ # Build amount string with cost basis if fiat_currency and fiat_amount and fiat_amount > 0: @@ -129,23 +125,10 @@ def format_posting_with_cost( # No cost basis: "200000 SATS" amount_str = f"{amount_sats} SATS" - # Build metadata + # Build metadata (only include explicitly passed metadata, not redundant fiat info) + # The cost syntax "{69.00 EUR}" already contains all fiat/exchange rate information posting_meta = metadata or {} - if fiat_currency and fiat_amount and fiat_amount > 0: - # Store fiat information in metadata for easy access - posting_meta["fiat-currency"] = fiat_currency - posting_meta["fiat-amount"] = str(abs(fiat_amount)) - posting_meta["sats-equivalent"] = str(abs(amount_sats)) - - # Calculate exchange rate (sats per fiat unit) - exchange_rate = abs(amount_sats) / abs(fiat_amount) - posting_meta["exchange-rate"] = f"{exchange_rate:.2f}" - - # Calculate BTC rate (fiat per BTC) - btc_rate = abs(fiat_amount) / abs(amount_sats) * 100_000_000 - posting_meta["btc-rate"] = f"{btc_rate:.2f}" - return { "account": account, "amount": amount_str, @@ -262,11 +245,11 @@ def format_expense_entry( ] # Build entry metadata + # Note: created-via is redundant with #expense-entry tag + # Note: is-equity is redundant with account name (Equity vs Liabilities:Payable) and tags entry_meta = { "user-id": user_id, - "source": "castle-api", - "created-via": "expense_entry", - "is-equity": "true" if is_equity else "false" + "source": "castle-api" } # Build links @@ -342,11 +325,11 @@ def format_receivable_entry( ) ] + # Note: created-via is redundant with #receivable-entry tag + # Note: debtor-user-id is the same as user-id for receivables (redundant) entry_meta = { "user-id": user_id, - "source": "castle-api", - "created-via": "receivable_entry", - "debtor-user-id": user_id + "source": "castle-api" } links = [] @@ -436,12 +419,11 @@ def format_payment_entry( ) ] + # Note: created-via is redundant with #lightning-payment tag + # Note: payer/payee can be inferred from transaction direction and accounts entry_meta = { "user-id": user_id, - "source": "lightning_payment", - "created-via": "payment_entry", - "payer-user-id": user_id if not is_payable else "castle", - "payee-user-id": user_id if is_payable else "castle" + "source": "lightning_payment" } if payment_hash: @@ -527,9 +509,9 @@ def format_revenue_entry( ) ] + # Note: created-via is redundant with #revenue-entry tag entry_meta = { - "source": "castle-api", - "created-via": "revenue_entry" + "source": "castle-api" } links = []