Implement hybrid approach for balance assertions

Balance assertions now use a hybrid architecture where Beancount is the source
of truth for validation, while Castle stores metadata for UI convenience.

Backend changes:
- Add format_balance() function to beancount_format.py for formatting balance directives
- Update POST /api/v1/assertions to write balance directive to Beancount first (via Fava)
- Store metadata in Castle DB (created_by, tolerance, notes) for UI features
- Validate assertions immediately by querying Fava for actual balance

Frontend changes:
- Update dialog description to explain Beancount validation
- Update button tooltip to clarify balance assertions are written to Beancount
- Update empty state message to mention Beancount checkpoints

Benefits:
- Single source of truth (Beancount ledger file)
- Automatic validation by Beancount
- Best of both worlds: robust validation + friendly UI

See misc-docs/BALANCE-ASSERTIONS-HYBRID-APPROACH.md for full documentation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
padreug 2025-11-10 20:46:12 +01:00
parent 28832d6bfe
commit a3c3e44e5f
3 changed files with 69 additions and 6 deletions

View file

@ -520,7 +520,7 @@
icon="add"
label="Create Assertion"
>
<q-tooltip>Create a new balance assertion for reconciliation</q-tooltip>
<q-tooltip>Write a balance assertion to Beancount ledger for automatic validation</q-tooltip>
</q-btn>
</div>
@ -629,7 +629,7 @@
<!-- No assertions message -->
<div v-if="balanceAssertions.length === 0" class="text-center text-grey q-pa-md">
No balance assertions yet. Create one to verify your accounting accuracy.
No balance assertions yet. Create one to add checkpoints to your Beancount ledger and verify accounting accuracy.
</div>
</q-card-section>
</q-card>
@ -1185,7 +1185,10 @@
<div class="text-h6 q-mb-md">Create Balance Assertion</div>
<div class="text-caption text-grey q-mb-md">
Balance assertions help you verify accounting accuracy by checking if an account's actual balance matches your expected balance. If the assertion fails, you'll be alerted to investigate the discrepancy.
Balance assertions are written to your Beancount ledger and validated automatically by Beancount.
This verifies that an account's actual balance matches your expected balance at a specific date.
If the assertion fails, Beancount will alert you to investigate the discrepancy. Castle stores
metadata (tolerance, notes) for your convenience.
</div>
<q-select