Track purchase refunds as reductions in spending

Closed
TA
16d ago
+2620-171

Adds purchase refunds as a separate transaction type that reduces category spending instead of inflating income. For example, buying $500 of clothes and returning $300 leaves $200 of spending. Users can optionally link a refund to its original purchase to see the final cost of the goods they keep.

  • Available through Preview features → transaction details → Purchase refund; supports marking, linking, and undoing refunds.

  • Supports partial and multiple refunds, different senders/currencies, and shipping or exchange-rate differences. Refunds reduce spending on their posting date; linked purchase net cost includes later refunds.

  • Adds refund badges, filters, and totals; applies the treatment across reports and budgets while preserving bank amounts.

  • API clients can create/classify, link, unlink, and undo refunds. Responses expose accessible purchase links and net cost while preserving existing cash-direction fields. Includes OpenAPI documentation.

  • The assistant identifies refunds separately from income and returns refund totals and the same purchase metadata.

Migration: adds a nullable, indexed transactions.refund_of_id self-reference. Existing transactions are not automatically reclassified.

Validation

  • Full Rails suite: 8,452 tests, 34,013 assertions; no failures or errors (30 skips).
  • Refund UI browser suite: 114 tests, 505 assertions; no failures, errors, or skips (verified before the API-only follow-up).
  • Ruby lint and Brakeman pass; OpenAPI generation and API consistency checks pass. Biome passed for the UI implementation. All nine changed ERB templates pass lint.
  • Production Docker image builds and boots; refund/reporting smoke test passes.
  • Full ERB lint has existing failures in unchanged upstream templates (impersonation bars, print layout, changelog, and avatar field), plus two unrelated autocorrections. These files are outside this PR.

Screenshots

Before: the return appears as income

Before refund classification

Mark an incoming payment as a refund

Mark as refund

Optionally link the original purchase

Link original purchase

Saved refund linked to its purchase

Saved linked refund

Summary by CodeRabbit

  • New Features

    • Mark transactions as purchase refunds, optionally link them to purchases, view net purchase costs, and undo refund status.
    • Search and filter transactions by refund type, with clear refund indicators and details.
    • Refunds are reflected in budgets, expense reports, dashboards, exports, imports, and transaction summaries.
    • Charts now display negative values, including refund credits.
    • Transaction APIs and assistant tools now support refund classification, linking, filtering, and net-cost details.
  • Bug Fixes

    • Refunds are excluded from recurring-income detection, recurring allocations, and transfer matching.
    • Added clearer validation and alerts for invalid refund, split, and transfer actions.
    • User-locked transaction classifications are now preserved.