From e429a6c6fd91ef6023562b04337985126ad49bdb Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Fri, 1 May 2020 16:24:24 -0400 Subject: [PATCH] meta_approval: Not required for chargebacks. RT#10978. --- conservancy_beancount/plugin/meta_approval.py | 6 +++++- tests/test_meta_approval.py | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/conservancy_beancount/plugin/meta_approval.py b/conservancy_beancount/plugin/meta_approval.py index 31fdc88..be3a24b 100644 --- a/conservancy_beancount/plugin/meta_approval.py +++ b/conservancy_beancount/plugin/meta_approval.py @@ -44,4 +44,8 @@ class MetaApproval(core._RequireLinksPostingMetadataHook): ) def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool: - return post.account.is_cash_equivalent() and post.units.number < 0 + return ( + post.account.is_cash_equivalent() + and post.units.number < 0 + and post.meta.get('tax-implication', '').title() != 'Chargeback' + ) diff --git a/tests/test_meta_approval.py b/tests/test_meta_approval.py index 2edc1e2..5d17785 100644 --- a/tests/test_meta_approval.py +++ b/tests/test_meta_approval.py @@ -159,10 +159,14 @@ def test_approval_not_required_to_pay_credit_card(hook): ]) assert not list(hook.run(txn)) -def test_approval_not_required_for_asset_transfers(hook): +@pytest.mark.parametrize('tax_implication,other_acct', [ + ('Bank-Transfer', 'Assets:Savings'), + ('Chargeback', 'Income:Donations'), +]) +def test_approval_not_required_for_asset_transfers(hook, tax_implication, other_acct): txn = testutil.Transaction(postings=[ - ('Assets:Checking', -250, {'tax-implication': 'Bank-Transfer'}), - ('Assets:Savings', 250), + ('Assets:Checking', -250, {'tax-implication': tax_implication}), + (other_acct, 250), ]) assert not list(hook.run(txn))