feat(accounts): show when an account's balance drifts from its transaction history
Ready to merge
GF
9d ago+1242+1242+0123456789012345678901234567890123456789-12-12-01234567890123456789
Summary
- Adds
Balance::IntegrityChecker, a read-only check over an account'sValuationwaypoints (opening_anchor,reconciliation,current_anchor).Balance::ReverseCalculatorresets the balance to the bank-reported value at every reconciliation waypoint, so drift from missing or duplicated transactions is absorbed without being recorded anywhere. This is the first place that surfaces that drift. - Shows it as a per-account status, as agreed in #5162: while a gap is open, it is one of the account's
Account::HealthStatusissues (since #5363), next to the sync state under the account header. It says how much higher or lower the bank's balance is than the transactions add up to, since when, and links to the account's transactions since the last date both agreed. It is computed when the page renders, for that one account, so every member who can open the account sees it, private accounts included. - Scope: only linked
DepositoryandCreditCardaccounts with entries in a single currency (Balance::IntegrityChecker.open_gap_for). On manual accounts a mismatch is the user's own choice, not a data error. - Same-day timing: a linked account's snapshot is the balance at sync time, not at the end of the day. A busy day's snapshot can miss any subset of that day's bookings and pending amounts, so it never opens a gap on its own, and it keeps, changes or closes an open gap only as far as those subsets allow. A gap must stay open longer than 4 days (
MIN_DAYS_OPEN) before it shows, since some banks take weekend card payments off the reported balance at once but book them only on Tuesday.
Test plan
-
Balance::IntegrityCheckerTest: 32 cases, including persistent and self-resolving gaps, split and excluded transactions, liability signs, linked accounts with late same-day bookings and pending holds, gaps that close or partly close on busy days, and the eligibility rules ofopen_gap_for. -
Account::HealthStatusTestandUI::Account::HealthStatusTest: the gap issue, its link to the transactions since the last match, and the amount and date in the family's date format. -
AccountsControllerTest: the warning shows for a linked account with an open gap (amount, direction, link), stays away while bank and transactions agree, and shows for a private account to its owner. - Full
bin/rails test,bin/rubocop,erb_lintandbin/brakemanpass.
Strings are in en, de and es.