Improves readability and reduces logging verbosity
Removes excessive logging to improve readability and reduce verbosity. Streamlines balance processing and improves logging for settlement amounts. Adds a note about Fava's internal normalization behavior to the beancount formatting.
This commit is contained in:
parent
313265b185
commit
fbda8e2980
3 changed files with 7 additions and 24 deletions
|
|
@ -193,12 +193,9 @@ class FavaClient:
|
|||
# Get all journal entries for this user
|
||||
all_entries = await self.get_journal_entries()
|
||||
|
||||
logger.info(f"Processing {len(all_entries)} journal entries for user {user_id[:8]}")
|
||||
|
||||
total_sats = 0
|
||||
fiat_balances = {}
|
||||
accounts_dict = {} # Track balances per account
|
||||
processed_count = 0
|
||||
|
||||
for entry in all_entries:
|
||||
# Skip non-transactions, pending (!), and voided
|
||||
|
|
@ -209,11 +206,6 @@ class FavaClient:
|
|||
if "voided" in entry.get("tags", []):
|
||||
continue
|
||||
|
||||
# Check if this entry has any User-375ec158 postings
|
||||
has_user_posting = any(f":User-{user_id[:8]}" in p.get("account", "") for p in entry.get("postings", []))
|
||||
if has_user_posting:
|
||||
logger.info(f"Entry '{entry.get('narration', 'N/A')}' has {len(entry.get('postings', []))} postings")
|
||||
|
||||
# Process postings for this user
|
||||
for posting in entry.get("postings", []):
|
||||
account_name = posting.get("account", "")
|
||||
|
|
@ -229,9 +221,6 @@ class FavaClient:
|
|||
if not isinstance(amount_str, str) or not amount_str:
|
||||
continue
|
||||
|
||||
logger.info(f"Processing posting in {account_name}: amount_str='{amount_str}'")
|
||||
processed_count += 1
|
||||
|
||||
import re
|
||||
# Try to extract EUR/USD amount first (new format)
|
||||
fiat_match = re.match(r'^(-?[\d.]+)\s+([A-Z]{3})$', amount_str)
|
||||
|
|
@ -244,7 +233,6 @@ class FavaClient:
|
|||
fiat_balances[fiat_currency] = Decimal(0)
|
||||
|
||||
fiat_balances[fiat_currency] += fiat_amount
|
||||
logger.info(f"Found fiat in {account_name}: {fiat_amount} {fiat_currency} (direct), running total: {fiat_balances[fiat_currency]}")
|
||||
|
||||
# Also track SATS equivalent from metadata if available
|
||||
posting_meta = posting.get("meta", {})
|
||||
|
|
@ -288,16 +276,13 @@ class FavaClient:
|
|||
fiat_total = -fiat_total
|
||||
|
||||
fiat_balances[fiat_currency] += fiat_total
|
||||
logger.info(f"Found fiat in {account_name}: {fiat_total} {fiat_currency} (from SATS metadata), running total: {fiat_balances[fiat_currency]}")
|
||||
|
||||
result = {
|
||||
logger.info(f"User {user_id[:8]} balance: {total_sats} sats, fiat: {dict(fiat_balances)}")
|
||||
return {
|
||||
"balance": total_sats,
|
||||
"fiat_balances": fiat_balances,
|
||||
"accounts": list(accounts_dict.values())
|
||||
}
|
||||
logger.info(f"Processed {processed_count} postings for user {user_id[:8]}")
|
||||
logger.info(f"Returning balance for user {user_id[:8]}: sats={total_sats}, fiat_balances={fiat_balances}")
|
||||
return result
|
||||
|
||||
async def get_all_user_balances(self) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue