Changeset - 4789972d3811
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-23 13:51:47
brettcsmith@brettcsmith.org
approval: Not required for any bank transfer. RT#11707.
2 files changed with 8 insertions and 14 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/plugin/meta_approval.py
Show inline comments
...
 
@@ -24,12 +24,16 @@ from ..beancount_types import (
 
    Transaction,
 
)
 

	
 
class MetaApproval(core._RequireLinksPostingMetadataHook):
 
    CHECKED_METADATA = ['approval']
 
    SKIP_FLAGS = '!'
 
    SKIP_TAX_IMPLICATIONS = frozenset([
 
        'Bank-Transfer',
 
        'Chargeback',
 
    ])
 

	
 
    def __init__(self, config: configmod.Config) -> None:
 
        self.payment_threshold = -config.payment_threshold()
 

	
 
    def _run_on_txn(self, txn: Transaction) -> bool:
 
        return (
...
 
@@ -45,8 +49,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
 
            and post.meta.get('tax-implication', '').title() != 'Chargeback'
 
            and str(post.meta.get('tax-implication')).title() not in self.SKIP_TAX_IMPLICATIONS
 
        )
tests/test_meta_approval.py
Show inline comments
...
 
@@ -160,30 +160,20 @@ def test_approval_not_required_to_pay_credit_card(hook):
 
    assert not list(hook.run(txn))
 

	
 
@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):
 
def test_approval_not_required_by_tax_implication(hook, tax_implication, other_acct):
 
    txn = testutil.Transaction(postings=[
 
        ('Assets:Checking', -250, {'tax-implication': tax_implication}),
 
        (other_acct, 250),
 
        (other_acct, 245),
 
        ('Expenses:BankingFees', 5),
 
    ])
 
    assert not list(hook.run(txn))
 

	
 
def test_approval_required_for_partial_transfer(hook):
 
    # I'm not sure this ever comes up in reality, but just being thorough
 
    # out of an abundance of precaution.
 
    txn = testutil.Transaction(postings=[
 
        ('Assets:Checking', -250, {'tax-implication': 'Bank-Transfer'}),
 
        ('Assets:Savings', 225),
 
        ('Expenses:BankingFees', 25),
 
    ])
 
    actual = {error.message for error in hook.run(txn)}
 
    assert actual == {"Assets:Checking missing {}".format(TEST_KEY)}
 

	
 
def test_not_required_on_flagged(hook):
 
    txn = testutil.Transaction(flag='!', postings=[
 
        ('Assets:Checking', -25),
 
        ('Liabilities:Payable:Accounts', 25),
 
    ])
 
    assert not list(hook.run(txn))
0 comments (0 inline, 0 general)