Changeset - dbe8d02b7807
[Not reviewed]
0 1 0
Ben Sturmfels (bsturmfels) - 2 years ago 2022-01-27 23:11:48
ben@sturm.com.au
reconcile: Update helper to show N/A when no results, similar to Perl.

Also clarified that a full account name should be passed. This aligns with the
Perl behaviour.
1 file changed with 19 insertions and 8 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reconcile/helper.py
Show inline comments
...
 
@@ -33,18 +33,26 @@ def end_of_month(date):
 

	
 

	
 
def format_record_for_grep(row, homedir):
 
    """Return a line in a grep-style.
 

	
 
    This is so the line can be fed into Emacs grep-mode for quickly jumping to
 
    the relevant lines in the books.
 
    """
 
    file = row[0].replace(homedir, '~')
 
    return [f'{file}:{row[1]}:'] + row[2:]
 

	
 

	
 
def max_column_widths(rows):
 
    """Return the max width for each column in a table of data."""
 
    maxes = [0] * len(rows[0])
 
    for row in rows:
 
        for i, val in enumerate(row):
 
            length = len(str(val))
 
            maxes[i] = max(maxes[i], length)
 
    return maxes
 
    if not rows:
 
        return []
 
    else:
 
        maxes = [0] * len(rows[0])
 
        for row in rows:
 
            for i, val in enumerate(row):
 
                length = len(str(val))
 
                maxes[i] = max(maxes[i], length)
 
        return maxes
 

	
 

	
 
def tabulate(rows, headers=None):
...
 
@@ -68,10 +76,11 @@ def tabulate(rows, headers=None):
 
        print('', file=output)
 
    return output.getvalue().strip()
 

	
 

	
 
# Parse all the arguments
 
parser = argparse.ArgumentParser(description='Reconciliation helper')
 
parser.add_argument('--beancount-file', required=True)
 
parser.add_argument('--account', help='Account regexp', required=True)
 
parser.add_argument('--account', help='Full account name, e.g. "Liabilities:CreditCard:AMEX"', required=True)
 
parser.add_argument('--prev-end-date', type=datetime.date.fromisoformat)
 
parser.add_argument('--cur-end-date', type=datetime.date.fromisoformat)
 
parser.add_argument('--month', help='YYYY-MM of ending month. Use with --period.')
...
 
@@ -156,7 +165,9 @@ print(f"START RECONCILIATION FOR {account} ENDING {lastDateInPeriod} (previous e
 
entries, _, options = loader.load_file(beancount_file)
 
for desc, query in QUERIES.items():
 
    rtypes, rrows = run_query(entries, options, query, numberify=True)
 
    if desc.startswith('04'):
 
    if not rrows:
 
        print(f'{desc:<55} N/A')
 
    elif desc.startswith('04'):
 
        homedir = os.getenv('HOME')
 
        print(f'{desc}\n   See {grep_output_file.name}')
 
        grep_rows = [format_record_for_grep(row, homedir) for row in rrows]
0 comments (0 inline, 0 general)