From 3330c834b2222c410ef96b6c755dcfdfa4c92221 2020-06-12 14:51:29 From: Brett Smith Date: 2020-06-12 14:51:29 Subject: [PATCH] accrual: Only try to generate an outgoing report for accruals with rt-id. --- diff --git a/conservancy_beancount/reports/accrual.py b/conservancy_beancount/reports/accrual.py index 30e0fb58cfbf4c791ae5f3f8bab7d346abedad46..f68d1abf31646df12606b95205af8b55c6544943 100644 --- a/conservancy_beancount/reports/accrual.py +++ b/conservancy_beancount/reports/accrual.py @@ -701,8 +701,10 @@ def main(arglist: Optional[Sequence[str]]=None, groups = dict(AccrualPostings.group_by_first_meta_link(postings, 'rt-id')) if (args.report_type is None and len(groups) == 1 - and all(g.accrual_type is AccrualAccount.PAYABLE and not g.is_paid() - for g in groups.values()) + and all(group.accrual_type is AccrualAccount.PAYABLE + and not group.is_paid() + and key # Make sure we have a usable rt-id + for key, group in groups.items()) ): args.report_type = ReportType.OUTGOING if args.report_type is not ReportType.OUTGOING: diff --git a/setup.py b/setup.py index 7b0f64268c502658541863173f1ec34119a9b2a2..94576a1b99c79d1d47a4257ba72471945610da3e 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.1.10', + version='1.1.11', author='Software Freedom Conservancy', author_email='info@sfconservancy.org', license='GNU AGPLv3+', diff --git a/tests/books/accruals.beancount b/tests/books/accruals.beancount index aa6bc85fc8a9dc399bbd037bade920f39143bae8..229a4830dae5ed9b9fdc72e97426326366d3219b 100644 --- a/tests/books/accruals.beancount +++ b/tests/books/accruals.beancount @@ -143,6 +143,13 @@ Expenses:FilingFees 60.00 USD Liabilities:Payable:Accounts -60.00 USD +2010-06-15 * "GrantCo" "2010Q2 grant" + rt-id: "rt:470" + invoice: "rt:470/4700" + project: "Development Grant" + Assets:Receivable:Accounts 5500 USD + Income:Donations -5500 USD + 2010-06-18 * "EuroGov" "European legal fees" ; Multiple rt-ids are used to test proper handling for both ; searching and generating the outgoing report. @@ -153,12 +160,12 @@ Liabilities:Payable:Accounts -1,000 EUR {1.100 USD} Expenses:FilingFees 1,000 EUR {1.100 USD} -2010-06-15 * "GrantCo" "2010Q2 grant" - rt-id: "rt:470" - invoice: "rt:470/4700" - project: "Development Grant" - Assets:Receivable:Accounts 5500 USD - Income:Donations -5500 USD +2010-06-20 * "StateGov" "Business registration" + ; Intentionally has no rt-id + invoice: "Invoices/2010StateRegistration.pdf" + project: "Conservancy" + Liabilities:Payable:Accounts -50 USD + Expenses:FilingFees 50 USD 2010-09-15 * "GrantCo" "2010Q3 grant" rt-id: "rt:470" diff --git a/tests/test_reports_accrual.py b/tests/test_reports_accrual.py index 676d2ae4986627bb49f0ee4f0ccfa862707e0ca6..fec4b0e736bb0bc0fae2a9e9e58688af7a4a890e 100644 --- a/tests/test_reports_accrual.py +++ b/tests/test_reports_accrual.py @@ -79,7 +79,7 @@ class AgingRow(NamedTuple): date = datetime.datetime.strptime(date, '%Y-%m-%d').date() if not isinstance(at_cost, tuple): at_cost = testutil.Amount(at_cost) - if rt_id is None: + if rt_id is None and invoice.startswith('rt:'): rt_id, _, _ = invoice.partition('/') return cls(date, [entity], orig_amount, at_cost, [rt_id], [invoice], [project]) @@ -111,6 +111,7 @@ AGING_AP = [ AgingRow.make_simple('2010-06-10', 'Lawyer', 280, 'rt:510/6100'), AgingRow.make_simple('2010-06-18', 'EuroGov', 1100, 'rt:520/5200', orig_amount=[testutil.Amount(1000, 'EUR')]), + AgingRow.make_simple('2010-06-20', 'StateGov', 50, 'Invoices/2010StateRegistration.pdf'), ] AGING_AR = [ @@ -654,6 +655,16 @@ def test_main_balance_report(arglist): r'^\s+1,500\.00 USD outstanding since 2010-05-15$', ]) +def test_main_balance_report_because_no_rt_id(): + invoice = 'Invoices/2010StateRegistration.pdf' + retcode, output, errors = run_main([invoice]) + assert not errors.getvalue() + assert retcode == 0 + check_output(output, [ + rf'\b{re.escape(invoice)}:$', + r'^\s+-50\.00 USD outstanding since 2010-06-20$', + ]) + @pytest.mark.parametrize('arglist', [ [], ['-t', 'aging', 'entity=Lawyer'],