From 517d4027b462cfcb4f4d4c504d1d5be46e8f336d 2022-02-21 11:43:22 From: Ben Sturmfels Date: 2022-02-21 11:43:22 Subject: [PATCH] reconcile: Explicitly avoid payee matching when check-id provided in books. --- diff --git a/conservancy_beancount/reconcile/prototype_amex_reconciler.py b/conservancy_beancount/reconcile/prototype_amex_reconciler.py index 274c6928da459c707d0ba12e90ea6265410a3eca..3d6cc87addeaa747ecfbb84650063bd31d125e33 100644 --- a/conservancy_beancount/reconcile/prototype_amex_reconciler.py +++ b/conservancy_beancount/reconcile/prototype_amex_reconciler.py @@ -223,7 +223,7 @@ def records_match(r1: Dict, r2: Dict) -> Tuple[bool, str]: if r1['check_id'] and r2['check_id'] and r1['check_id'] == r2['check_id']: check_score = 1.0 else: - check_message = 'Check id not matched' + check_message = 'check-id mismatch' check_score = 0.0 else: check_score = 0.0 @@ -267,7 +267,7 @@ def match_statement_and_books(statement_trans: list, books_trans: list): best_match_score = score best_match_index = i best_match_note = note - if best_match_score > 0.5 and matches_found == 1 and 'payee_mismatch' not in best_match_note or best_match_score > 0.8: + if best_match_score > 0.5 and matches_found == 1 and 'check-id mismatch' not in best_match_note or best_match_score > 0.8: if best_match_score <= 0.8: best_match_note.append('only one decent match') matches.append(([r1], [books_trans[best_match_index]], best_match_note)) diff --git a/tests/test_reconcile.py b/tests/test_reconcile.py index ba3d33b469849cdae095543f65d2b92225fee1de..186b5e5ca650736102d7b69f2f83dfef83f50d4a 100644 --- a/tests/test_reconcile.py +++ b/tests/test_reconcile.py @@ -100,6 +100,15 @@ B3_payee_mismatch_2 = { 'line': 999, 'bank_statement': "Financial/Bank-Statements/AMEX/2022-01-12_AMEX_statement.pdf" } +B3_unmatched_check_id = { + 'date': datetime.date(2022, 1, 3), + 'amount': decimal.Decimal('30.00'), + 'payee': 'USPS', + 'check_id': '1234', + 'filename': '2022/main.beancount', + 'line': 999, + 'bank_statement': "Financial/Bank-Statements/AMEX/2022-01-12_AMEX_statement.pdf" +} def test_one_exact_match(): @@ -230,3 +239,13 @@ def test_totals(): ([S2], [], []), ([], [B3_next_day], []), ]) == (decimal.Decimal('10'), decimal.Decimal('20'), decimal.Decimal('30')) + + +def test_payee_not_considered_if_check_id_present(): + # These records match aside from check-id. + statement = [S3] + books = [B3_unmatched_check_id] + assert match_statement_and_books(statement, books) == [ + ([S3], [], ['no match']), + ([], [B3_unmatched_check_id], ['no match']), + ]