Changeset - 9ae36feed2f8
[Not reviewed]
0 1 0
Ben Sturmfels (bsturmfels) - 2 years ago 2022-02-24 10:11:02
ben@sturm.com.au
reconciler: Remove debug warning.
1 file changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reconcile/statement_reconciler.py
Show inline comments
...
 
@@ -120,24 +120,29 @@ def remove_payee_junk(payee: str) -> str:
 
    payee = ' '.join([i for i in payee.split(' ') if len(i) > 2])
 
    payee = payee.replace('-', ' ')
 
    payee = remove_duplicate_words(payee)
 
    payee.strip()
 
    return payee
 

	
 
# NOTE: Statement doesn't seem to give us a running balance or a final total.
 

	
 
def read_transactions_from_csv(f: TextIO, standardize_statement_record: Callable) -> list:
 
    reader = csv.DictReader(f)
 
    return sort_records([standardize_statement_record(row, reader.line_num) for row in reader])
 

	
 
# Does the account you entered match the CSV?
 
# Is the CSV in the format we expect? (ie. did they download through the right interface?)
 
# Logical CSV line numbers
 
# CSV reconciliation report
 
# Merge helper script.
 

	
 
def standardize_amex_record(row: Dict, line: int) -> Dict:
 
    """Turn an AMEX CSV row into a standard dict format representing a transaction."""
 
    return {
 
        'date': datetime.datetime.strptime(row['Date'], '%m/%d/%Y').date(),
 
        'amount': -1 * decimal.Decimal(row['Amount']),
 
        # Descriptions have too much noise, so taking just the start
 
        # significantly assists the fuzzy matching.
 
        'payee': remove_payee_junk(row['Description'] or '')[:20],
 
        'check_id': '',
 
        'line': line,
 
    }
...
 
@@ -242,51 +247,46 @@ def records_match(r1: Dict, r2: Dict) -> Tuple[bool, str]:
 
        elif payee_score > 0.4:
 
            payee_message = 'partial payee match'
 
        else:
 
            payee_message = 'payee mismatch'
 

	
 
    overall_score = (date_score + amount_score + check_score + payee_score) / 4
 
    overall_message = [m for m in [date_message, amount_message, check_message, payee_message] if m]
 
    return overall_score, overall_message
 

	
 

	
 
def match_statement_and_books(statement_trans: list, books_trans: list):
 
    """
 

	
 

	
 
    Runs through all the statement transactions to find a matching transaction
 
    in the books. If found, the books transaction is marked off so that it can
 
    only be matched once. Some transactions will be matched, some will be on the
 
    statement but not the books and some on the books but not the statement.
 

	
 
    """
 
    matches = []
 
    remaining_books_trans = []
 
    remaining_statement_trans = []
 

	
 
    for r1 in statement_trans:
 
        best_match_score = 0
 
        best_match_index = None
 
        best_match_note = ''
 
        matches_found = 0
 
        for i, r2 in enumerate(books_trans):
 
            score, note = records_match(r1, r2)
 
            if score >= 0.5 and score >= best_match_score:
 
                matches_found += 1
 
                best_match_score = score
 
                best_match_index = i
 
                best_match_note = note
 
        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))
 
            # Don't try to make a second match against this books entry.
 
            del books_trans[best_match_index]
 
        else:
 
            remaining_statement_trans.append(r1)
 
    for r2 in books_trans:
 
        remaining_books_trans.append(r2)
 
    return matches, remaining_statement_trans, remaining_books_trans
 

	
 

	
 
def format_matches(matches, csv_statement: str, show_reconciled_matches):
 
    match_output = []
0 comments (0 inline, 0 general)