Changeset - 21852845c0f4
[Not reviewed]
0 1 0
Ben Sturmfels (bsturmfels) - 3 years ago 2022-02-09 01:32:14
ben@sturm.com.au
reconcile: Remove debugging lines.
1 file changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reconcile/prototype_amex_reconciler.py
Show inline comments
...
 
@@ -133,61 +133,61 @@ result_types, result_rows = run_query(
 
)
 

	
 

	
 
books_trans = sort_records([standardize_beancount_record(row) for row in result_rows])
 

	
 
num_statement_records = len(statement_trans)
 
num_books_trans = len(books_trans)
 
statement_index = 0
 
books_index = 0
 
matches = []
 
metadata_to_apply = []
 

	
 
# Run 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.
 
for r1 in statement_trans:
 
    for r2 in books_trans:
 
        match, note = records_match(r1, r2)
 
        if match:
 
            if not r2['statement'] or args.show_reconciled_matches:
 
                    matches.append([r2['date'], f'{format_record(r1)}    -->    {format_record(r2)}  ✓ {note}'])
 
            if not r2['statement']:
 
                metadata_to_apply.append((r2['filename'], r2['line'], f'    bank-statement: "{args.csv_statement}"\n'))
 
            books_trans.remove(r2)
 
            break
 
    else:
 
        matches.append([r1['date'], f'{format_record(r1)}    -->    {" ":^44}  ✗ Not in books'])
 
for r2 in books_trans:
 
    matches.append([r2['date'], f'{" ":^44}    -->    {format_record(r2)}  ✗ Not on statement'])
 

	
 
print(f'-----------------------------------------------------------------------------------------------------------------')
 
print(f'{"STATEMENT":<40}            {"BOOKS":<40}   NOTES')
 
print(f'-----------------------------------------------------------------------------------------------------------------')
 
for _, output in sorted(matches):
 
    print(output)
 
print(f'-----------------------------------------------------------------------------------------------------------------')
 

	
 
# Write statement metadata back to books
 
if metadata_to_apply:
 
    print('Mark matched transactions as reconciled in the books? (y/N) ', end='')
 
    if input().lower() == 'y':
 
        files = {}
 
        # Query results aren't necessarily sequential in a file, so need to sort
 
        # so that our line number offsets work.
 
        for filename, line, metadata in sorted(metadata_to_apply):
 
            if filename not in files:
 
                with open(filename, 'r') as f:
 
                    print(f'Opening {filename}.')
 
                    # print(f'Opening {filename}.')
 
                    files[filename] = [0, f.readlines()]  # Offset and contents
 
            files[filename][1].insert(line + files[filename][0], metadata)
 
            files[filename][0] += 1
 
            print(f'File {filename} offset {files[filename][0]}')
 
            # print(f'File {filename} offset {files[filename][0]}')
 
        for filename in files:
 
            with open(filename, 'w') as f:
 
                f.writelines(files[filename][1])
 
                print(f'Wrote {filename}.')
 

	
 
# Local Variables:
 
# python-shell-interpreter: "/home/ben/\.virtualenvs/conservancy-beancount-py39/bin/python"
 
# End:
0 comments (0 inline, 0 general)