3.5 KiB
3.5 KiB
Ledger Integration Walkthrough
This document outlines the changes made to integrate Ledger functionality into the Transaction flow and provides steps for verification.
Changes Overview
Backend (Go)
TransactionInput: AddedLedgerIDfield to potential input.TransactionService:- Updated
CreateTransactionto assign the user's default ledger if noLedgerIDis provided. - Updated
CreateTransactionandUpdateTransactionto validate and link theLedgerID. - Injected
LedgerRepositoryto allow fetching default ledgers and validating IDs.
- Updated
Router: Updated dependency injection to passLedgerRepositorytoTransactionService.
Frontend (React/TypeScript)
- Global State: Created
SettingsContextto provide global access to the currently selectedledgerId. - Types: Updated
TransactionFormInput,TransactionFilter, and other interfaces to supportthis.ledgerId. - Service (
transactionService.ts): UpdatedgetTransactions,createTransaction, andupdateTransactionto mapledgerIdto the backend API parameters (ledger_id). - Components:
TransactionForm: Now acceptscurrentLedgerIdand submits it with new transactions.CommandPalette: Now filters transaction search results by the current active ledger.
- Pages:
Home: Updated to useSettingsContextfor ledger selection and data refreshing.Transactions: Updated to filter the transaction list by the globalcurrentLedgerIdand pass it to the creation form.
Verification Steps
1. Ledger Switching
- Navigate to the Home page.
- Click the Ledger selector in the header (top left pill).
- Select a different ledger (e.g., "Business" vs "Personal").
- Verify: The "Recent Transactions" list update to show only transactions for the selected ledger.
- Verify: The Dashboard stats (Income, Expense) update to reflect the selected ledger.
2. Transaction Creation with Ledger
- Ensure you are in a specific ledger (e.g., "Personal").
- Click "记一笔" (Add Transaction).
- Create a new transaction.
- Verify: The transaction appears in the "Personal" ledger list.
- Switch to a "Business" ledger.
- Verify: The newly created transaction does NOT appear in the "Business" ledger list.
3. Transaction List Filtering
- Go to the Transactions page.
- Verify: The list only shows transactions for the currently selected ledger.
- Switch ledger using the global context (if accessible) or go back Home to switch, then return.
- Verify: The list refreshes to show the new ledger's transactions.
4. Global Search
- Press
Ctrl+K(orCmd+K) to open the Command Palette. - Type a search term for a transaction that exists in the current ledger.
- Verify: The transaction appears in results.
- Type a search term for a transaction that exists in a different ledger.
- Verify: The transaction does NOT appear in results.
5. Exchange Rates (Regression Test)
- Go to Exchange Rates page.
- Verify: Net Worth and History still load correctly (this calculates based on global accounts, so it should remain unaffected by ledger selection).
Technical Notes
- Default Behavior: If a transaction is created via API without a
ledger_id(e.g., older clients), the backend now automatically assigns it to the user's Default Ledger. - Context Persistence: The selected ledger ID is stored in User Settings, so it persists across sessions if the backend supports saving settings (which it does).