From 78407779d60edc8305a4ebacecc801ab2a0dd8c4 Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Wed, 3 Sep 2025 13:44:34 +1000 Subject: [PATCH] reconciler: Handle whitespace-only Citizen Bank transaction description --- .../reconcile/statement_reconciler.py | 9 ++++---- setup.cfg | 2 +- tests/test_reconcile.py | 21 +++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/conservancy_beancount/reconcile/statement_reconciler.py b/conservancy_beancount/reconcile/statement_reconciler.py index c03b4e9..8aae77c 100644 --- a/conservancy_beancount/reconcile/statement_reconciler.py +++ b/conservancy_beancount/reconcile/statement_reconciler.py @@ -414,11 +414,12 @@ def first_word_exact_match(a: str, b: str) -> float: is useful and the rest is garbage. """ - if len(a) == 0 or len(b) == 0: + a_words, b_words = a.split(), b.split() + if len(a_words) == 0 or len(b_words) == 0: return 0.0 - first_a = a.split()[0].strip() - first_b = b.split()[0].strip() - if first_a.casefold() == first_b.casefold(): + first_a = a_words[0].strip().casefold() + first_b = b_words[0].strip().casefold() + if first_a == first_b: return min(1.0, 0.2 * len(first_a)) else: return 0.0 diff --git a/setup.cfg b/setup.cfg index 3b9ec57..1a88536 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = conservancy_beancount -version = 1.22.0 +version = 1.23.0 author = Software Freedom Conservancy author_email = info@sfconservancy.org description = Plugin, library, and reports for reading Conservancy’s books diff --git a/tests/test_reconcile.py b/tests/test_reconcile.py index a1ac7f2..ef28bb3 100644 --- a/tests/test_reconcile.py +++ b/tests/test_reconcile.py @@ -459,3 +459,24 @@ month_test_data = [ @pytest.mark.parametrize('input_dates,rounded_dates', month_test_data) def test_rounds_to_full_month(input_dates, rounded_dates): assert round_to_month(*input_dates) == rounded_dates + + +def test_handles_payee_whitespace_only(): + """Sometimes Citizen Bank statements have a single space in the transaction desc.""" + statement = [ + { + 'date': datetime.date(2022, 1, 1), + 'amount': decimal.Decimal('10.00'), + 'payee': ' ', + 'check_id': '', + } + ] + books = [ + { + 'date': datetime.date(2022, 1, 1), + 'amount': decimal.Decimal('10.00'), + 'payee': ' ', + 'check_id': '', + } + ] + assert match_statement_and_books(statement, books)