reconciler: Handle whitespace-only Citizen Bank transaction description

This commit is contained in:
Ben Sturmfels 2025-09-03 13:44:34 +10:00
parent e21142f0ba
commit 78407779d6
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
3 changed files with 27 additions and 5 deletions

View file

@ -414,11 +414,12 @@ def first_word_exact_match(a: str, b: str) -> float:
is useful and the rest is garbage. 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 return 0.0
first_a = a.split()[0].strip() first_a = a_words[0].strip().casefold()
first_b = b.split()[0].strip() first_b = b_words[0].strip().casefold()
if first_a.casefold() == first_b.casefold(): if first_a == first_b:
return min(1.0, 0.2 * len(first_a)) return min(1.0, 0.2 * len(first_a))
else: else:
return 0.0 return 0.0

View file

@ -1,6 +1,6 @@
[metadata] [metadata]
name = conservancy_beancount name = conservancy_beancount
version = 1.22.0 version = 1.23.0
author = Software Freedom Conservancy author = Software Freedom Conservancy
author_email = info@sfconservancy.org author_email = info@sfconservancy.org
description = Plugin, library, and reports for reading Conservancys books description = Plugin, library, and reports for reading Conservancys books

View file

@ -459,3 +459,24 @@ month_test_data = [
@pytest.mark.parametrize('input_dates,rounded_dates', month_test_data) @pytest.mark.parametrize('input_dates,rounded_dates', month_test_data)
def test_rounds_to_full_month(input_dates, rounded_dates): def test_rounds_to_full_month(input_dates, rounded_dates):
assert round_to_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)