Replace stored Enable Banking rows the bank redelivers with corrected data

Merged
GF
11d ago
+157-3

What this PR does

When Enable Banking delivers a transaction again with the same id but corrected data (amount, remittance text, counterparty), the corrected version now replaces the stored row in the raw transactions snapshot.

Before, the importer paired stored and fetched rows only by content. A row that kept its id but changed its content was not paired, so the stored row was retained and the fetched correction was dropped as already stored. The processor kept reading the old data forever.

Now a fetched row whose id matches a stored row also supersedes it. Stored rows keep their position, new rows are appended, and the snapshot is only rewritten when it actually changed. Rows that share a transaction_id are still told apart by entry_reference, as before.

This came out of the review of the IBAN series (#3511), where it was split into its own PR.

Validation

  • New tests in test/models/enable_banking_item/importer_pdng_test.rb. Two of them fail without this change: a corrected row replaces the stored one in place, and a reference-less row redelivered on the same date replaces the stored one. The other three are guards that also pass on main: an unchanged refetch skips the snapshot write, a pending row does not replace a booked one, and a reference-less row on another date that reuses a transaction_id does not replace the stored row.
  • Full Enable Banking model tests green, CI green.

Known limitation

Rows without an entry_reference are matched by transaction_id and booking date only. If a bank reuses a transaction_id for a different payment on the same day, the stored entry is now replaced by the new one. Before this change, the new row was dropped instead. In both cases one movement is lost, because a correction and a reuse look the same without a reference. A separate identity for reference-less rows is planned as a follow-up.


Summary by cubic

Fixes the Enable Banking importer so a transaction the bank redelivers with corrected data replaces the stored row.

Before, rows were paired only by content, so a refetch of the same id with a changed amount, remittance text, or counterparty was dropped as already stored and the processor kept reading the old data. Now a fetched row supersedes a stored row with the same id only when the id is unique on both sides, the entry_reference matches (or, without one, the date matches), and a pending row is not replacing a booked one. Stored rows keep their order, new rows are appended, and the snapshot is only rewritten when it actually changed.

Validation

  • New model tests cover corrected replacements, unchanged refetches skipping the snapshot write, and the pending and reused-id cases that must not replace a stored row.

Summary by CodeRabbit

  • Bug Fixes
    • Refetched transactions now update stored entries when their matching external ID and other identifying details confirm they are corrections, while preserving existing entry order. Pending transactions no longer overwrite booked entries, and reused IDs are distinguished by entry reference or booking date.
    • Unchanged transaction refetches no longer create a new snapshot.