fava_client.add_account: accept target_file + infer routing from account name #28

Closed
opened 2026-06-06 13:15:00 +00:00 by padreug · 0 comments
Owner

Companion to aiolabs/server-deploy ledger split. With per-purpose files (accounts/chart.beancount for static + admin-mutable, accounts/users.beancount for runtime user opens), libra's add_account must route its PUT /api/source write to the correct file rather than hardcoding the fava-reported root.

/api/add_entries doesn't support Open directives (see fava_client.py:1495 docstring), so the routing has to happen in libra; fava's account-regex insert_entry mechanism only applies to Transactions.

Work

  • fava_client.py:1484 — add target_file: Optional[str] = None to add_account
  • Add module-level _infer_target_file(account_name) helper:
    _USER_ACCT_RE = re.compile(r":User-[0-9a-f]{8}$")
    def _infer_target_file(account_name: str) -> str:
        return "accounts/users.beancount" if _USER_ACCT_RE.search(account_name) \
            else "accounts/chart.beancount"
    
  • Resolve target_file once before the retry loop
  • Drop the GET /api/options call (lines 1543–1547) — no longer needed
  • Replace file_path at lines 1554 (GET param) and 1602 (PUT payload) with target_file
  • Update docstring example at lines 1518–1529 to mention target_file as optional
  • Verify crud.py:253 caller (per-user signup) routes correctly via the inferred default
  • Verify approve/reject paths at views_api.py:2786, 2902 still work — they read meta["filename"] which Beancount preserves across includes. If fava returns relative paths, no change needed; if absolute, possibly normalise.

Acceptance

  • Unit test for _infer_target_file covers Assets:Receivable:User-abc12345 (→ users), Liabilities:Payable:User-deadbeef (→ users), Equity:MemberEquity:User-12345678 (→ users), Expenses:Other (→ chart), Assets:Bitcoin:Lightning (→ chart)
  • Dev-compose test: user creation lands an open in accounts/users.beancount; admin-created chart account lands in accounts/chart.beancount
  • Approve a !-flagged entry → transactions.beancount edited in place, * flag visible

Plan reference: ~/.claude/plans/elegant-bubbling-frog.md sections B.1 + B.2 + B.4.

Companion to `aiolabs/server-deploy` ledger split. With per-purpose files (`accounts/chart.beancount` for static + admin-mutable, `accounts/users.beancount` for runtime user opens), libra's `add_account` must route its `PUT /api/source` write to the correct file rather than hardcoding the fava-reported root. `/api/add_entries` doesn't support Open directives (see `fava_client.py:1495` docstring), so the routing has to happen in libra; fava's account-regex `insert_entry` mechanism only applies to Transactions. ## Work - [ ] `fava_client.py:1484` — add `target_file: Optional[str] = None` to `add_account` - [ ] Add module-level `_infer_target_file(account_name)` helper: ```python _USER_ACCT_RE = re.compile(r":User-[0-9a-f]{8}$") def _infer_target_file(account_name: str) -> str: return "accounts/users.beancount" if _USER_ACCT_RE.search(account_name) \ else "accounts/chart.beancount" ``` - [ ] Resolve `target_file` once before the retry loop - [ ] Drop the `GET /api/options` call (lines 1543–1547) — no longer needed - [ ] Replace `file_path` at lines 1554 (GET param) and 1602 (PUT payload) with `target_file` - [ ] Update docstring example at lines 1518–1529 to mention `target_file` as optional - [ ] Verify `crud.py:253` caller (per-user signup) routes correctly via the inferred default - [ ] **Verify** approve/reject paths at `views_api.py:2786, 2902` still work — they read `meta["filename"]` which Beancount preserves across includes. If fava returns relative paths, no change needed; if absolute, possibly normalise. ## Acceptance - Unit test for `_infer_target_file` covers `Assets:Receivable:User-abc12345` (→ users), `Liabilities:Payable:User-deadbeef` (→ users), `Equity:MemberEquity:User-12345678` (→ users), `Expenses:Other` (→ chart), `Assets:Bitcoin:Lightning` (→ chart) - Dev-compose test: user creation lands an `open` in `accounts/users.beancount`; admin-created chart account lands in `accounts/chart.beancount` - Approve a `!`-flagged entry → `transactions.beancount` edited in place, `*` flag visible Plan reference: `~/.claude/plans/elegant-bubbling-frog.md` sections B.1 + B.2 + B.4.
padreug referenced this issue from a commit 2026-06-07 14:34:49 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aiolabs/libra#28
No description provided.