Files
sure/test
Guillem Arias Fauste 5220bd527b fix(budgets): stop auto-matched transfers leaking into category cards (#1059) (#1588)
Refs #1059.

When you auto-match a $500 expense from your checking account against
the matching deposit on your credit card, the resulting transfer pair
was leaving traces in the per-card "Recent transactions" list under
each budget category card, even though the aggregate
`Budget#actual_spending` (via `IncomeStatement`) already excluded
`BUDGET_EXCLUDED_KINDS` (funds_movement / one_time / cc_payment) from
the totals. The user saw $X under the card while the totals showed
$X less.

Fix: extend the same exclusion to the drilldown list. The aggregate
and the list now agree.

```ruby
# app/controllers/budget_categories_controller.rb
@recent_transactions = @budget.transactions
                              .where.not(transactions: { kind: Transaction::BUDGET_EXCLUDED_KINDS })
```

`loan_payment` and `investment_contribution` are intentionally NOT in
`BUDGET_EXCLUDED_KINDS`, so those transfers still appear (they are
budget-tracked).

What this PR does NOT do:

  - It does not clear the matched transactions' `category_id` in the
    matcher itself. An earlier draft of this PR did, but codex
    correctly flagged that doing so causes data loss when a user
    rejects an incorrect auto-match: `Transfer#reject!` resets `kind`
    to `standard` but does not restore the previously-cleared
    category, permanently dropping the user's original
    categorisation. The controller filter alone is sufficient to fix
    the user-visible bug, and the inconsistency between
    `kind = funds_movement` and a retained category is harmless because
    every relevant view filters one or the other.

  - The mortgage scenario in #1059 (a `loan_payment` match showing as
    "Uncategorised" in the budget) isn't a leak; it is a missing
    feature. The matcher doesn't auto-assign a category to
    `loan_payment` rows the way #924 does for
    `investment_contribution`. The natural follow-up is a parallel
    `loan_payments_category` plus matcher / import-adapter
    auto-assignment, which deserves a maintainer signoff first.

Tests:

  - `BudgetCategoriesControllerTest#show drilldown excludes
    BUDGET_EXCLUDED_KINDS transfers from recent transactions`: a
    matched depository <-> CC pair does not appear in the
    Uncategorised drilldown after the matcher runs.
  - `BudgetCategoriesControllerTest#show drilldown still lists
    loan_payment transfers (intentionally budget-tracked)`: a matched
    depository <-> loan pair stays visible in the drilldown.

Suite: 3239 / 0 / 0 / 24 on the latest upstream/main. Lint clean.
2026-05-01 00:59:48 +02:00
..
2025-11-17 21:51:37 +01:00