feat: capture counterparty IBAN from Enable Banking transactions

Ready to merge
GF
11h ago
+1881-47

What this PR does

Reads the counterparty account of Enable Banking transactions and uses it only during the import. The full counterparty IBAN is never stored. Each transaction keeps:

  • counterparty_iban_last4: the last four characters of the counterparty IBAN, for display.
  • counterparty_reference_last4: the last four characters of a non-IBAN account reference, when the bank sends no IBAN.
  • counterparty_own_account_id: a link to the family's own account when the counterparty IBAN matches one of its accounts.

How the matching works

  • At import, the counterparty IBAN is compared with the IBANs of the family's own accounts (excluding the importing account itself).
  • When one IBAN backs several sub-accounts (for example multi-currency accounts), the account in the transaction's currency wins. If that is still ambiguous, no link is set.
  • User-modified transactions only get blank fields filled.
  • The values are carried over when a transaction is split and when a pending row is merged into its booked row.
  • When an account IBAN is added, changed or released later, a low-priority job relinks older Enable Banking transactions of that family from the raw payload Enable Banking already stores. No new copy of full IBANs is created. Excluded and import-locked entries are skipped.

Data model

  • Migration adds the three columns, a concurrent index and a foreign key to accounts with on_delete: :nullify (added unvalidated, then validated).

Validation

  • Full Rails test suite green locally, CI green.
  • New tests for the rematcher, the own-account link, the sub-account currency preference, ties without a link, and corrected IBANs dropping the link.

Related

Depends on #3510 (do not merge before that one). Part of the Discussion #3115 series.

Summary by CodeRabbit

  • New Features
    • Enable Banking transactions now display the bank name in the account’s language when available.
    • Transactions can show counterparty account details, including the identifier type and final four characters, and link to a matching account you own.
  • Bug Fixes
    • Improved transaction matching to keep distinct transactions with different counterparty accounts while consolidating duplicates.
    • Counterparty details are better preserved when pending transactions become booked, transactions are split, or accounts are updated.