Changeset - 1cc4e732f4e2
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-10-21 14:51:18
brettcsmith@brettcsmith.org
accrual: Add --end option.

For assemble-audit-reports as shown.
2 files changed with 21 insertions and 3 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/accrual.py
Show inline comments
...
 
@@ -658,24 +658,32 @@ def parse_arguments(arglist: Optional[Sequence[str]]=None) -> argparse.Namespace
 
given, `outgoing` for search terms that return a single outstanding payable,
 
and `balance` any other time.
 
""")
 
    parser.add_argument(
 
        '--since',
 
        metavar='YEAR',
 
        type=int,
 
        default=0,
 
        help="""How far back to search the books for related transactions.
 
You can either specify a fiscal year, or a negative offset from the current
 
fiscal year, to start loading entries from. The default is to load the current,
 
unaudited books.
 
""")
 
    parser.add_argument(
 
        '--end', '--stop', '-e',
 
        dest='stop_date',
 
        metavar='DATE',
 
        type=cliutil.date_arg,
 
        help="""Do not consider entries from this date forward, in YYYY-MM-DD
 
format.
 
""")
 
    parser.add_argument(
 
        '--output-file', '-O',
 
        metavar='PATH',
 
        type=Path,
 
        help="""Write the report to this file, or stdout when PATH is `-`.
 
The default is stdout for the balance and outgoing reports, and a generated
 
filename for other reports.
 
""")
 
    cliutil.add_loglevel_argument(parser)
 
    parser.add_argument(
 
        'search_terms',
...
 
@@ -714,25 +722,30 @@ def main(arglist: Optional[Sequence[str]]=None,
 
        returncode = cliutil.ExitCode.NoConfiguration
 
    else:
 
        load_since = None if args.report_type == ReportType.AGING else args.since
 
        entries, load_errors, _ = books_loader.load_all(load_since)
 
        if load_errors:
 
            returncode = cliutil.ExitCode.BeancountErrors
 
        elif not entries:
 
            returncode = cliutil.ExitCode.NoDataLoaded
 
    filters.remove_opening_balance_txn(entries)
 
    for error in load_errors:
 
        bc_printer.print_error(error, file=stderr)
 

	
 
    postings_src = data.Posting.from_entries(entries)
 
    stop_date = args.stop_date or datetime.date(datetime.MAXYEAR, 12, 31)
 
    postings_src: Iterator[data.Posting] = (
 
        posting
 
        for posting in data.Posting.from_entries(entries)
 
        if posting.meta.date < stop_date
 
    )
 
    for rewrite_path in args.rewrite_rules:
 
        try:
 
            ruleset = rewrite.RewriteRuleset.from_yaml(rewrite_path)
 
        except ValueError as error:
 
            logger.critical("failed loading rewrite rules from %s: %s",
 
                            rewrite_path, error.args[0])
 
            return cliutil.ExitCode.RewriteRulesError
 
        postings_src = ruleset.rewrite(postings_src)
 
    postings = list(filter_search(postings_src, args.search_terms))
 
    if not postings:
 
        logger.warning("no matching entries found to report")
 
        returncode = returncode or cliutil.ExitCode.NoDataFiltered
...
 
@@ -766,25 +779,25 @@ def main(arglist: Optional[Sequence[str]]=None,
 
    output_path: Optional[Path] = None
 
    if args.report_type is ReportType.AGING:
 
        rt_wrapper = config.rt_wrapper()
 
        if rt_wrapper is None:
 
            logger.error("unable to generate aging report: RT client is required")
 
        else:
 
            if args.output_file is None:
 
                now = datetime.datetime.now()
 
                out_dir_path = config.repository_path() or Path()
 
                args.output_file = out_dir_path / now.strftime('AgingReport_%Y-%m-%d_%H:%M.ods')
 
                logger.info("Writing report to %s", args.output_file)
 
            out_bin = cliutil.bytes_output(args.output_file, stdout)
 
            report = AgingReport(rt_wrapper, out_bin)
 
            report = AgingReport(rt_wrapper, out_bin, args.stop_date)
 
            report.ods.set_common_properties(config.books_repo())
 
    elif args.report_type is ReportType.OUTGOING:
 
        rt_wrapper = config.rt_wrapper()
 
        if rt_wrapper is None:
 
            logger.error("unable to generate outgoing report: RT client is required")
 
        else:
 
            out_file = cliutil.text_output(args.output_file, stdout)
 
            report = OutgoingReport(rt_wrapper, out_file)
 
    else:
 
        out_file = cliutil.text_output(args.output_file, stdout)
 
        report = BalanceReport(out_file)
 

	
conservancy_beancount/tools/audit_report.py
Show inline comments
...
 
@@ -175,25 +175,30 @@ def main(arglist: Optional[Sequence[str]]=None,
 
            yield f'--rewrite-rules={path}'
 
        yield f'--output-file={out_path}'
 
        yield from arglist
 
    reports: List[Tuple[ReportFunc, ArgList]] = [
 
        # Reports are sorted roughly in descending order of how long each takes
 
        # to generate.
 
        (ledger.main, list(common_args('GeneralLedger', args.audit_year))),
 
        (ledger.main, list(common_args('GeneralLedger', next_year))),
 
        (ledger.main, list(common_args('Disbursements', args.audit_year, '--disbursements'))),
 
        (ledger.main, list(common_args('Receipts', args.audit_year, '--receipts'))),
 
        (ledger.main, list(common_args('Disbursements', next_year, '--disbursements'))),
 
        (ledger.main, list(common_args('Receipts', next_year, '--receipts'))),
 
        (accrual.main, list(common_args('AgingReport.ods'))),
 
        (accrual.main, list(common_args(f'FY{next_year}AgingReport.ods'))),
 
        (accrual.main, list(common_args(
 
            f'FY{args.audit_year}AgingReport.ods',
 
            None,
 
            f'--end={audit_end.isoformat()}',
 
        ))),
 
        (balance_sheet.main, list(common_args('Summary', args.audit_year))),
 
        (fund.main, list(common_args('FundReport', args.audit_year))),
 
        (fund.main, list(common_args('FundReport', next_year))),
 
    ]
 

	
 
    books = config.books_loader()
 
    if books is None:
 
        logger.critical("no books available to load")
 
        return os.EX_NOINPUT
 

	
 
    with futmod.ProcessPoolExecutor(args.jobs) as pool:
 
        logger.debug("%s: process pool ready with %s workers", now_s(), args.jobs)
0 comments (0 inline, 0 general)