fix(enable-banking): preserve claimed pending date on subsequent syncs (#1797)

After the first sync claims a pending entry (setting auto_claimed_pending_ids),
subsequent syncs find the entry by booked external_id as an existing record.
pending_match is never entered so pending_entry_date stays nil, causing
`nil || date` to silently overwrite the preserved pending date with the
booked settlement date.

Fix by checking auto_claimed_pending_ids on the existing entry — its presence
signals a prior auto-claim, so entry.date (the original pending date) is kept.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
CrossDrain
2026-05-14 21:33:22 +02:00
committed by GitHub
co-authored by Claude Sonnet 4.6
parent 81e66870d7
commit c106aaf10d
2 changed files with 63 additions and 1 deletions
+16 -1
View File
@@ -137,10 +137,25 @@ class Account::ProviderImportAdapter
# Track if this is a new posted transaction (for fuzzy suggestion after save)
is_new_posted = entry.new_record? && !incoming_pending
# Preserve the original pending date across all syncs:
# - First claim: pending_entry_date is captured from the pending match above
# - Subsequent syncs: entry already exists (no pending_match found), so check
# auto_claimed_pending_ids which signals it was previously auto-claimed and
# keep entry.date (the pending date stored on first claim) unchanged
effective_date = if pending_entry_date
pending_entry_date
elsif !entry.new_record? &&
entry.entryable.is_a?(Transaction) &&
entry.transaction.extra&.key?("auto_claimed_pending_ids")
entry.date
else
date
end
entry.assign_attributes(
amount: amount,
currency: currency,
date: pending_entry_date || date
date: effective_date
)
# Use enrichment pattern to respect user overrides