Changeset - 35804db617a1
[Not reviewed]
0 7 0
Brett Smith - 4 years ago 2020-08-31 18:19:00
brettcsmith@brettcsmith.org
reports: All reports support rewrite rules.

I realized that if ledger-report supported rewrite rules, then it would
include all the information necessary to reproduce the numbers on the
statement of functional expenses.

With that, it was easy enough to add support to the rest of the reports for
consistency's sake.
7 files changed with 51 insertions and 20 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/cliutil.py
Show inline comments
...
 
@@ -121,2 +121,3 @@ class ExitCode(enum.IntEnum):
 
    NoDataLoaded = os.EX_NOINPUT
 
    RewriteRulesError = os.EX_DATAERR
 

	
...
 
@@ -255,2 +256,13 @@ def add_loglevel_argument(parser: argparse.ArgumentParser,
 

	
 
def add_rewrite_rules_argument(parser: argparse.ArgumentParser) -> argparse.Action:
 
    return parser.add_argument(
 
        '--rewrite-rules', '--rewrites', '-r',
 
        action='append',
 
        default=[],
 
        metavar='PATH',
 
        type=Path,
 
        help="""Use rewrite rules from the given YAML file. You can specify
 
this option multiple times to load multiple sets of rewrite rules in order.
 
""")
 

	
 
def add_version_argument(parser: argparse.ArgumentParser) -> argparse.Action:
conservancy_beancount/reports/accrual.py
Show inline comments
...
 
@@ -117,2 +117,3 @@ from beancount.parser import printer as bc_printer
 
from . import core
 
from . import rewrite
 
from .. import books
...
 
@@ -649,2 +650,3 @@ def parse_arguments(arglist: Optional[Sequence[str]]=None) -> argparse.Namespace
 
    cliutil.add_version_argument(parser)
 
    cliutil.add_rewrite_rules_argument(parser)
 
    parser.add_argument(
...
 
@@ -723,5 +725,12 @@ def main(arglist: Optional[Sequence[str]]=None,
 

	
 
    postings = list(filter_search(
 
        data.Posting.from_entries(entries), args.search_terms,
 
    ))
 
    postings_src = data.Posting.from_entries(entries)
 
    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:
conservancy_beancount/reports/balance_sheet.py
Show inline comments
...
 
@@ -22,3 +22,2 @@ import logging
 
import operator
 
import os
 
import sys
...
 
@@ -635,11 +634,3 @@ The default is a year after the start date.
 
""")
 
    parser.add_argument(
 
        '--rewrite-rules', '--rewrites', '-r',
 
        action='append',
 
        default=[],
 
        metavar='PATH',
 
        type=Path,
 
        help="""Use rewrite rules from the given YAML file. You can specify
 
this option multiple times to load multiple sets of rewrite rules in order.
 
""")
 
    cliutil.add_rewrite_rules_argument(parser)
 
    parser.add_argument(
...
 
@@ -707,3 +698,3 @@ def main(arglist: Optional[Sequence[str]]=None,
 
                            rewrite_path, error.args[0])
 
            return os.EX_DATAERR
 
            return cliutil.ExitCode.RewriteRulesError
 
        postings = ruleset.rewrite(postings)
conservancy_beancount/reports/fund.py
Show inline comments
...
 
@@ -76,2 +76,3 @@ from beancount.parser import printer as bc_printer
 
from . import core
 
from . import rewrite
 
from .. import books
...
 
@@ -310,2 +311,3 @@ The default is a year after the start date.
 
""")
 
    cliutil.add_rewrite_rules_argument(parser)
 
    parser.add_argument(
...
 
@@ -380,3 +382,3 @@ def main(arglist: Optional[Sequence[str]]=None,
 

	
 
    postings = (
 
    postings = iter(
 
        post
...
 
@@ -385,2 +387,10 @@ def main(arglist: Optional[Sequence[str]]=None,
 
    )
 
    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 = ruleset.rewrite(postings)
 
    for search_term in args.search_terms:
conservancy_beancount/reports/ledger.py
Show inline comments
...
 
@@ -80,2 +80,3 @@ from beancount.parser import printer as bc_printer
 
from . import core
 
from . import rewrite
 
from .. import books
...
 
@@ -703,2 +704,3 @@ search criteria.
 
""")
 
    cliutil.add_rewrite_rules_argument(parser)
 
    parser.add_argument(
...
 
@@ -799,2 +801,10 @@ def main(arglist: Optional[Sequence[str]]=None,
 
    postings = data.Posting.from_entries(entries)
 
    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 = ruleset.rewrite(postings)
 
    for search_term in args.search_terms:
conservancy_beancount/tools/audit_report.py
Show inline comments
...
 
@@ -198,2 +198,4 @@ def main(arglist: Optional[Sequence[str]]=None,
 
        output_reports.append(out_path)
 
        for path in args.rewrite_rules:
 
            yield f'--rewrite-rules={path}'
 
        yield f'--output-file={out_path}'
...
 
@@ -210,6 +212,3 @@ def main(arglist: Optional[Sequence[str]]=None,
 
        (accrual.main, list(common_args('AgingReport.ods'))),
 
        (balance_sheet.main, list(common_args(
 
            'Summary', args.audit_year,
 
            *(f'--rewrite-rules={path}' for path in args.rewrite_rules),
 
        ))),
 
        (balance_sheet.main, list(common_args('Summary', args.audit_year))),
 
        (fund.main, list(common_args('FundReport', args.audit_year))),
setup.py
Show inline comments
...
 
@@ -7,3 +7,3 @@ setup(
 
    description="Plugin, library, and reports for reading Conservancy's books",
 
    version='1.9.0',
 
    version='1.9.1',
 
    author='Software Freedom Conservancy',
0 comments (0 inline, 0 general)