Open-source personal finance manager. Self-hosted, privacy-first.
fix(import): keep OFX rows that share a FITID but differ in amount (#998)
Tássio Noronhabf9ede59d948
diff --git a/backend/app/services/import_service.py b/backend/app/services/import_service.pyindex 45071117..046baf03 100644--- a/backend/app/services/import_service.py+++ b/backend/app/services/import_service.py@@ -788,7 +788,9 @@ async def import_transactions(if should_detect_duplicates:# Prefer an external ID (OFX FITID), with date retained because some- # Brazilian cards reuse one purchase FITID across monthly installments.+ # Brazilian cards reuse one purchase FITID across monthly installments,+ # and amount and type retained because some banks reuse one FITID for+ # several distinct entries posted on the same day.# Formats without unique IDs fall back to transaction fields; compare# both descriptions because rules may have changed the displayed one.if txn_data.external_id:@@ -796,6 +798,8 @@ async def import_transactions(Transaction.account_id == account_id,Transaction.external_id == txn_data.external_id,Transaction.date == txn_data.date,+ Transaction.amount == txn_data.amount,+ Transaction.type == txn_data.type,)else:existing_statement = select(Transaction).where(diff --git a/backend/tests/test_import_service.py b/backend/tests/test_import_service.pyindex 772eb5ac..6ab493c2 100644--- a/backend/tests/test_import_service.py+++ b/backend/tests/test_import_service.py@@ -2058,6 +2058,47 @@ class TestOfxInstallmentDedup:assert skipped == 2+ @pytest.mark.asyncio+ async def test_same_external_id_same_date_different_amounts_all_imported(+ self, session: AsyncSession, test_user: User, test_workspace, test_account: Account,+ ):+ """Some banks reuse one FITID for several entries on the same day+ (issue #911). Each distinct amount must be imported, and re-importing+ the same file must still skip all of them."""+ from app.schemas.transaction import TransactionImport++ rows = [+ TransactionImport(+ description=memo,+ amount=Decimal(amount),+ date=date(2026, 7, 1),+ type="credit",+ external_id="101.820.900.050.894",+ )+ for memo, amount in [+ ("Rende Facil 1", "1.72"),+ ("Rende Facil 2", "3.04"),+ ("Rende Facil 3", "2.85"),+ ]+ ]+ imported, skipped, _, _ = await import_transactions(+ session, test_workspace.id, test_user.id, test_account.id, rows, "ofx",+ )+ assert imported == 3+ assert skipped == 0++ imported2, skipped2, _, _ = await import_transactions(+ session,+ test_workspace.id,+ test_user.id,+ test_account.id,+ [r.model_copy() for r in rows],+ "ofx",+ )+ assert imported2 == 0+ assert skipped2 == 3++class TestCsvDuplicateDetectionToggle:@pytest.mark.asyncioasync def test_csv_identical_new_rows_remain_distinct(