From efe9bd88550d4a204ac41d0792bdd14c4574a508 2020-06-16 17:31:46 From: Brett Smith Date: 2020-06-16 17:31:46 Subject: [PATCH] ledger: Change default report dates. The old defaults were optimized for the audit report. The new defaults provide more helpful ad hoc reports. The latter will be run more often and more quickly, so it's worth optimizing the defaults for them. --- diff --git a/conservancy_beancount/reports/ledger.py b/conservancy_beancount/reports/ledger.py index d9e332557463063fd3d904445b71293a549a0169..2c2460972ed2b87a1f4ed4e3bdbc7341a5170066 100644 --- a/conservancy_beancount/reports/ledger.py +++ b/conservancy_beancount/reports/ledger.py @@ -417,7 +417,7 @@ def parse_arguments(arglist: Optional[Sequence[str]]=None) -> argparse.Namespace metavar='DATE', type=cliutil.date_arg, help="""Date to start reporting entries, inclusive, in YYYY-MM-DD format. -The default is the beginning of the last full fiscal year. +The default is one year ago. """) parser.add_argument( '--end', '--stop', '-e', @@ -425,7 +425,8 @@ The default is the beginning of the last full fiscal year. metavar='DATE', type=cliutil.date_arg, help="""Date to stop reporting entries, exclusive, in YYYY-MM-DD format. -The default is the end of the begin date's fiscal year. +The default is a year after the start date, or 30 days from today if the start +date was also not specified. """) parser.add_argument( '--account', '-a', @@ -472,6 +473,17 @@ metadata to match. A single ticket number is a shortcut for args.sheet_names = list(LedgerODS.ACCOUNT_COLUMNS) return args +def diff_year(date: datetime.date, diff: int) -> datetime.date: + new_year = date.year + diff + try: + return date.replace(year=new_year) + except ValueError: + # The original date is Feb 29, which doesn't exist in the new year. + if diff < 0: + return datetime.date(new_year, 2, 28) + else: + return datetime.date(new_year, 3, 1) + def main(arglist: Optional[Sequence[str]]=None, stdout: TextIO=sys.stdout, stderr: TextIO=sys.stderr, @@ -483,11 +495,13 @@ def main(arglist: Optional[Sequence[str]]=None, config = configmod.Config() config.load_file() - fy = config.fiscal_year_begin() + today = datetime.date.today() if args.start_date is None: - args.start_date = fy.first_date(fy.for_date() - 1) - if args.stop_date is None: - args.stop_date = fy.next_fy_date(args.start_date) + args.start_date = diff_year(today, -1) + if args.stop_date is None: + args.stop_date = today + datetime.timedelta(days=30) + elif args.stop_date is None: + args.stop_date = diff_year(args.start_date, 1) returncode = 0 books_loader = config.books_loader() diff --git a/setup.py b/setup.py index 762787058720e4649482f181d750e3529186a5c8..57db701fa7b4d862f72fa5ea762dbd49465594a5 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup setup( name='conservancy_beancount', description="Plugin, library, and reports for reading Conservancy's books", - version='1.2.0', + version='1.2.1', author='Software Freedom Conservancy', author_email='info@sfconservancy.org', license='GNU AGPLv3+',