From f9411e0ffe7924d81e3ec4ebc750167f45692108 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Mon, 22 Jun 2020 16:33:43 -0400 Subject: [PATCH] meta_receipt: Not required on interest income. RT#11695. --- conservancy_beancount/plugin/meta_receipt.py | 12 ++++++++++++ setup.py | 2 +- tests/test_meta_receipt.py | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/conservancy_beancount/plugin/meta_receipt.py b/conservancy_beancount/plugin/meta_receipt.py index c679020..8cc9508 100644 --- a/conservancy_beancount/plugin/meta_receipt.py +++ b/conservancy_beancount/plugin/meta_receipt.py @@ -36,6 +36,18 @@ class MetaReceipt(core._RequireLinksPostingMetadataHook): def __init__(self, config: configmod.Config) -> None: self.payment_threshold = abs(config.payment_threshold()) + def _run_on_txn(self, txn: Transaction) -> bool: + if not super()._run_on_txn(txn): + return False + elif (all(post.account.startswith('Assets:') for post in txn.postings + if post.units.number and post.units.number > 0) + and all(post.account == 'Income:Interest' for post in txn.postings + if post.units.number and post.units.number < 0) + ): + return False + else: + return True + def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool: return ( (post.account.is_cash_equivalent() or post.account.is_credit_card()) diff --git a/setup.py b/setup.py index 60c10d6..1cae3a0 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.3.0', + version='1.3.1', author='Software Freedom Conservancy', author_email='info@sfconservancy.org', license='GNU AGPLv3+', diff --git a/tests/test_meta_receipt.py b/tests/test_meta_receipt.py index 842064e..d189c9b 100644 --- a/tests/test_meta_receipt.py +++ b/tests/test_meta_receipt.py @@ -344,6 +344,24 @@ def test_fallback_on_zero_amount_postings(hook, test_pair, other_acct, value): ]) assert not list(hook.run(txn)) +@pytest.mark.parametrize('test_acct', ( + acct for acct in ACCOUNTS + if acct.name.startswith('Assets:') + and acct.required_types & PostType.CREDIT +)) +def test_not_required_on_interest(hook, test_acct): + check(hook, test_acct, 'Income:Interest', None, + check_type=PostType.CREDIT) + +@pytest.mark.parametrize('test_acct', ( + acct for acct in ACCOUNTS + if acct.name.startswith('Assets:') + and acct.required_types & PostType.DEBIT +)) +def test_required_on_reverse_interest(hook, test_acct): + check(hook, test_acct, 'Income:Interest', {test_acct.missing_message()}, + check_type=PostType.DEBIT) + @pytest.mark.parametrize('test_acct,equity_acct', testutil.combine_values( ACCOUNTS, testutil.OPENING_EQUITY_ACCOUNTS,