From 5793a55dbcc6d992bc9fa209ce9c3d4a4af68504 2023-02-11 07:54:52 From: Ben Sturmfels Date: 2023-02-11 07:54:52 Subject: [PATCH] reconciler: Fix reconciler lumping unmatched books items together (#20737) Issue was that the subset matching was passing through the grouped transactions rather than the original transactions when it failed to match. --- diff --git a/conservancy_beancount/reconcile/statement_reconciler.py b/conservancy_beancount/reconcile/statement_reconciler.py index bf83e56b68407a1f1921d4f94d77da327dc14968..d5e27520ab5609f72b4eb53e163e79ec298cb9c0 100644 --- a/conservancy_beancount/reconcile/statement_reconciler.py +++ b/conservancy_beancount/reconcile/statement_reconciler.py @@ -503,7 +503,7 @@ def subset_match( if best_match_index is not None: del statement_trans[best_match_index] else: - remaining_books_trans.append(r2) + remaining_books_trans.extend(group_items) for r1 in statement_trans: remaining_statement_trans.append(r1) return matches, remaining_statement_trans, remaining_books_trans diff --git a/tests/test_reconcile.py b/tests/test_reconcile.py index ba6d6ac655118e61351e7ca7e679fc6afed46f9d..90f8cf4dee45ac25aae543a85b737244abddd970 100644 --- a/tests/test_reconcile.py +++ b/tests/test_reconcile.py @@ -350,6 +350,33 @@ def test_subset_passes_through_all_non_matches(): ) +def test_subset_passes_though_unmatched_transactions_with_same_payee(): + # Tracy noticed that when multiple books payments had the same date and + # payee and were unmatched, they were being displayed lumped together, when + # they should have remained separate. + B1a = { + 'date': datetime.date(2022, 1, 1), + 'amount': decimal.Decimal('100.00'), + 'payee': 'Hannah', + 'check_id': '', + 'filename': '2022/imports.beancount', + 'line': 777, + 'bank_statement': '', + } + B1b = { + 'date': datetime.date(2022, 1, 1), + 'amount': decimal.Decimal('100.00'), + 'payee': 'Hannah', + 'check_id': '', + 'filename': '2022/imports.beancount', + 'line': 797, + 'bank_statement': '', + } + assert subset_match([], [B1a, B1b]) == ( + [], [], [B1a, B1b], # No match: two preserved intact + ) + + def test_handles_amex_csv(): CSV = """Date,Receipt,Description,Card Member,Account #,Amount,Extended Details,Appears On Your Statement As,Address,City/State,Zip Code,Country,Reference,Category\n08/19/2021,,Gandi.net San Francisco,RODNEY R BROWN,-99999,28.15,"00000009999 00000009999999999999\nGandi.net\nSan Francisco\n00000009999999999999",Gandi.net San Francisco,"NEPTUNUSSTRAAT 41-63\nHOOFDDORP",,2132 JA,NETHERLANDS (THE),'999999999999999999',Merchandise & Supplies-Internet Purchase\n""" expected = [