Changeset - 72385fd0bd64
[Not reviewed]
0 1 0
Ben Sturmfels (bsturmfels) - 2 years ago 2022-02-24 09:58:04
ben@sturm.com.au
reconcile: Quote metadata, fix hiding of matched + reconciled lines.
1 file changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reconcile/statement_reconciler.py
Show inline comments
...
 
@@ -285,25 +285,25 @@ def match_statement_and_books(statement_trans: list, books_trans: list):
 
            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 = []
 
    for r1s, r2s, note in matches:
 
        note = ', '.join(note)
 
        note = ': ' + note if note else note
 
        if r1s and r2s:
 
            if show_reconciled_matches and all(x['bank_statement'] for x in r2s):
 
            if show_reconciled_matches or not all(x['bank_statement'] for x in r2s):
 
                if len(r2s) == 1:
 
                    match_output.append([r1s[0]['date'], f'{format_record(r1s[0])}  →  {format_record(r2s[0])}  ✓ Matched{note}'])
 
                else:
 
                    match_output.extend(format_multirecord(r1s, r2s, note))
 
        elif r1s:
 
            match_output.append([r1s[0]['date'], Fore.RED + Style.BRIGHT + f'{format_record(r1s[0])}  →  {" ":^59}  ✗ NOT IN BOOKS ({os.path.basename(csv_statement)}:{r1s[0]["line"]})' + Style.RESET_ALL])
 
        else:
 
            match_output.append([r2s[0]['date'], Fore.RED + Style.BRIGHT + f'{" ":^59}  →  {format_record(r2s[0])}  ✗ NOT ON STATEMENT ({os.path.basename(r2s[0]["filename"])}:{r2s[0]["line"]})' + Style.RESET_ALL])
 
    return match_output
 

	
 

	
 
def date_proximity(d1, d2):
...
 
@@ -313,26 +313,26 @@ def date_proximity(d1, d2):
 
    else:
 
        return 1.0 - (diff / 60.0)
 

	
 
def metadata_for_match(match, statement_filename, csv_filename):
 
    # Can we really ever have multiple statement entries? Probably not.
 
    statement_filename = get_repo_relative_path(statement_filename)
 
    csv_filename = get_repo_relative_path(csv_filename)
 
    metadata = []
 
    statement_entries, books_entries, _ = match
 
    for books_entry in books_entries:
 
        for statement_entry in statement_entries:
 
            if not books_entry['bank_statement']:
 
                metadata.append((books_entry['filename'], books_entry['line'], f'    bank-statement: {statement_filename}'))
 
                metadata.append((books_entry['filename'], books_entry['line'], f'    bank-statement-csv: {csv_filename}:{statement_entry["line"]}'))
 
                metadata.append((books_entry['filename'], books_entry['line'], f'    bank-statement: "{statement_filename}"'))
 
                metadata.append((books_entry['filename'], books_entry['line'], f'    bank-statement-csv: "{csv_filename}:{statement_entry["line"]}"'))
 
    return metadata
 

	
 

	
 
# TODO: Is there a way to pull the side-effecting code out of this function?
 

	
 
def write_metadata_to_books(metadata_to_apply: List[Tuple[str, int, str]]) -> None:
 
    """Insert reconciliation metadata in the books files.
 

	
 
    Takes a list of edits to make as tuples of form (filename, lineno, metadata):
 

	
 
    [
 
        ('2021/main.beancount', 4245, '    bank-statement: statement.pdf'),
0 comments (0 inline, 0 general)