fix: Duplikat-Recheck beim Confirm nur statement-uebergreifend

Zwei identische Buchungen im selben Auszug teilen sich den dedup_hash. Beim
Confirm markierte die zuerst bestaetigte Buchung ihren Zwilling (autoflush +
Clash-Select) als Duplikat und uebersprang ihn, wodurch der vom Preview
gepruefte Saldo zerstoert wurde. Clash-Query um statement_id != tx.statement_id
erweitert: der Re-Check schuetzt nur noch statement-uebergreifend. Test: Auszug
mit zwei identischen Buchungen -> beide werden bestaetigt.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-17 20:16:08 +02:00
parent cf9282c716
commit 917797bb16
2 changed files with 43 additions and 0 deletions

View File

@@ -133,6 +133,11 @@ def confirm(statement_id: int, session: Session = Depends(get_session)):
Transaction.dedup_hash == tx.dedup_hash,
Transaction.status == "confirmed",
Transaction.id != tx.id,
# Only guard against duplicates from OTHER statements. Two
# genuinely identical bookings within the same statement share a
# dedup_hash; the balance the preview validated depends on both
# being confirmed, so they must not knock each other out here.
Transaction.statement_id != tx.statement_id,
)
).scalar()
if clash is not None: