Changeset - 517d4027b462
[Not reviewed]
0 2 0
Ben Sturmfels (bsturmfels) - 2 years ago 2022-02-21 11:43:22
ben@sturm.com.au
reconcile: Explicitly avoid payee matching when check-id provided in books.
2 files changed with 21 insertions and 2 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reconcile/prototype_amex_reconciler.py
Show inline comments
...
 
@@ -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))
tests/test_reconcile.py
Show inline comments
...
 
@@ -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']),
 
    ]
0 comments (0 inline, 0 general)