From 708d48699ae31a4811ddcc95883e96e60d1b85e3 2020-07-20 19:13:20 From: Brett Smith Date: 2020-07-20 19:13:20 Subject: [PATCH] accrual: Restore "since last nonzero" behavior to outgoing report. Basically this behavior is an extension of the fact that the outgoing report is grouped by RT ticket rather than "accrual data." Ripping this functionality out of other reports was correct, but it needed to stay for the outgoing report. --- diff --git a/conservancy_beancount/reports/accrual.py b/conservancy_beancount/reports/accrual.py index 71531daeb42df8f831f5c62cb0144dbb1f50cd11..085c7750627f0c12ad77eac000f9f12120f07d15 100644 --- a/conservancy_beancount/reports/accrual.py +++ b/conservancy_beancount/reports/accrual.py @@ -539,6 +539,15 @@ class OutgoingReport(BaseReport): ) requestor = f'{requestor_name} <{rt_requestor["EmailAddress"]}>'.strip() + last_zero_index = -1 + for index, (post, balance) in enumerate(posts.iter_with_balance()): + if balance.is_zero(): + prior_zero_index = last_zero_index + last_zero_index = index + if last_zero_index == index: + last_zero_index = prior_zero_index + posts = posts[last_zero_index + 1:] + balance = -posts.balance_at_cost() balance_s = balance.format(None) raw_balance = -posts.balance() diff --git a/setup.py b/setup.py index bfd468a73c5365c13c6eb91ec1fc1073f29917fe..0baea20754f1e684a7730611ee5e9708d2cbd9e9 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.5.10', + version='1.5.11', author='Software Freedom Conservancy', author_email='info@sfconservancy.org', license='GNU AGPLv3+', diff --git a/tests/test_reports_accrual.py b/tests/test_reports_accrual.py index fc1e197a0d4348edba9aaa243d78b6424318b2a5..c98295905cafd16d4e3cadb51bd05d10f8c82f38 100644 --- a/tests/test_reports_accrual.py +++ b/tests/test_reports_accrual.py @@ -510,9 +510,16 @@ def test_outgoing_report(accrual_postings, caplog): r'^TOTAL TO PAY: \$280\.00$', fr'^AGREEMENT: {contract_url}', r'^BEANCOUNT ENTRIES:$', - # For each transaction, check for the date line, a metadata, and the - # Expenses posting. - r'^\s*2010-06-10\s', + ]) + # Find the date line of the first transaction. + # For each transaction, check for the date line, a metadata, and the + # Expenses posting. + for line in output: + if not line.isspace(): + break + assert re.match(r'\s*2010-06-10\s', line), \ + "first entry line did not have expected date" + check_output(output, [ fr'^\s+rt-id: "{rt_id_url}"$', r'^\s+Expenses:Services:Legal\s+220\.00 USD$', r'^\s*2010-06-10\s',