Filter synthetic Beancount entries from journal listings

The Recent Transactions card was showing Beancount-generated opening-balance
entries from ledger summarization (flag 'S'). Adds a _SYNTHETIC_FLAGS set
mirroring Fava's _EXCL_FLAGS (S/T/C/P/U/R/M) and skips matching entries in
the two user-facing endpoints that previously only filtered by transaction
type. Other journal callers already filter by flag '!' so are unaffected.

Closes #3

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Padreug 2026-05-07 09:43:32 +02:00
commit 4085280711

View file

@ -94,6 +94,12 @@ from .auth import (
libra_api_router = APIRouter() libra_api_router = APIRouter()
# Synthetic Beancount flags marking auto-generated entries (summarization,
# padding, transfers, conversions, unrealized gains, returns, merging) that
# should not appear in user-facing transaction lists. Mirrors Fava's
# _EXCL_FLAGS in fava/core/file.py.
_SYNTHETIC_FLAGS = frozenset({"S", "T", "C", "P", "U", "R", "M"})
# ===== HELPER FUNCTIONS ===== # ===== HELPER FUNCTIONS =====
@ -391,6 +397,8 @@ async def api_get_journal_entries(
for e in all_entries: for e in all_entries:
if e.get("t") != "Transaction": if e.get("t") != "Transaction":
continue continue
if e.get("flag") in _SYNTHETIC_FLAGS:
continue
# Extract user ID from metadata or account names # Extract user ID from metadata or account names
user_id = None user_id = None
@ -475,6 +483,8 @@ async def api_get_user_entries(
for e in all_entries: for e in all_entries:
if e.get("t") != "Transaction": if e.get("t") != "Transaction":
continue continue
if e.get("flag") in _SYNTHETIC_FLAGS:
continue
# Skip voided transactions # Skip voided transactions
if "voided" in e.get("tags", []): if "voided" in e.get("tags", []):