Changeset - 0caf78436fe9
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-17 19:32:08
brettcsmith@brettcsmith.org
accrual: Generate an aging report in more cases.

Default to generating an aging report unless the user searched for a
specific RT ticket or invoice.
2 files changed with 26 insertions and 24 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/accrual.py
Show inline comments
...
 
@@ -8,4 +8,3 @@ accruals.
 

	
 
If you run it with no arguments, it will generate an aging report in ODS format
 
in the current directory.
 
If you run it with no arguments, it will generate an aging report in ODS format.
 

	
...
 
@@ -40,13 +39,15 @@ You can pass any number of search terms. For example::
 
accrual-report will automatically decide what kind of report to generate
 
from the search terms you provide and the results they return. If you pass
 
no search terms, it generates an aging report. If your search terms match a
 
single outstanding payable, it writes an outgoing approval report.
 
Otherwise, it writes a basic balance report. You can specify what report
 
from the search terms you provide and the results they return. If you
 
searched on an RT ticket or invoice that returned a single outstanding
 
payable, it writes an outgoing approval report. If you searched on RT ticket
 
or invoice that returned other results, it writes a balance
 
report. Otherwise, it writes an aging report. You can specify what report
 
type you want with the ``--report-type`` option::
 

	
 
    # Write an outgoing approval report for all outstanding accruals for
 
    # Write an outgoing approval report for all outstanding payables for
 
    # Jane Doe, even if there's more than one
 
    accrual-report --report-type outgoing entity=Doe-Jane
 
    # Write an aging report for a specific project
 
    accrual-report --report-type aging project=ProjectName
 
    # Write an aging report for a single RT invoice (this can be helpful when
 
    # one invoice covers multiple parties)
 
    accrual-report --report-type aging 12/345
 
"""
...
 
@@ -629,3 +630,6 @@ metadata to match. A single ticket number is a shortcut for
 
    args = parser.parse_args(arglist)
 
    if args.report_type is None and not args.search_terms:
 
    if args.report_type is None and not any(
 
            term.meta_key == 'invoice' or term.meta_key == 'rt-id'
 
            for term in args.search_terms
 
    ):
 
        args.report_type = ReportType.AGING
tests/test_reports_accrual.py
Show inline comments
...
 
@@ -579,3 +579,3 @@ def test_aging_report_does_not_include_too_recent_postings(accrual_postings):
 

	
 
def run_main(arglist, config=None):
 
def run_main(arglist, config=None, out_type=io.StringIO):
 
    if config is None:
...
 
@@ -585,5 +585,9 @@ def run_main(arglist, config=None):
 
        )
 
    output = io.StringIO()
 
    if out_type is io.BytesIO:
 
        arglist.insert(0, '--output-file=-')
 
    output = out_type()
 
    errors = io.StringIO()
 
    retcode = accrual.main(arglist, output, errors, config)
 
    output.seek(0)
 
    errors.seek(0)
 
    return retcode, output, errors
...
 
@@ -595,3 +599,2 @@ def check_main_fails(arglist, config, error_flags):
 
    assert not output.getvalue()
 
    errors.seek(0)
 
    return errors
...
 
@@ -626,3 +629,3 @@ def test_output_payments_when_only_match(arglist, expect_invoice):
 
    (['310/3120'], 220),
 
    (['entity=Vendor'], 420),
 
    (['-t', 'out', 'entity=Vendor'], 420),
 
])
...
 
@@ -645,3 +648,2 @@ def test_main_outgoing_report(arglist, expect_amount):
 
    ['515/5150'],
 
    ['entity=MatchingProgram'],
 
])
...
 
@@ -668,5 +670,5 @@ def test_main_balance_report_because_no_rt_id():
 
    [],
 
    ['-t', 'aging', 'entity=Lawyer'],
 
    ['entity=Lawyer'],
 
])
 
def test_main_aging_report(tmp_path, arglist):
 
def test_main_aging_report(arglist):
 
    if arglist:
...
 
@@ -677,10 +679,6 @@ def test_main_aging_report(tmp_path, arglist):
 
        pay_rows = AGING_AP
 
    output_path = tmp_path / 'AgingReport.ods'
 
    arglist.insert(0, f'--output-file={output_path}')
 
    retcode, output, errors = run_main(arglist)
 
    retcode, output, errors = run_main(arglist, out_type=io.BytesIO)
 
    assert not errors.getvalue()
 
    assert retcode == 0
 
    assert not output.getvalue()
 
    with output_path.open('rb') as ods_file:
 
        check_aging_ods(ods_file, None, recv_rows, pay_rows)
 
    check_aging_ods(output, None, recv_rows, pay_rows)
 

	
...
 
@@ -695,3 +693,3 @@ def test_main_no_books():
 
    ['505/99999'],
 
    ['entity=NonExistent'],
 
    ['-t', 'balance', 'entity=NonExistent'],
 
])
0 comments (0 inline, 0 general)