approval: Not required for any bank transfer. RT#11707.

This commit is contained in:
Brett Smith 2020-06-23 09:51:12 -04:00
parent f9411e0ffe
commit 4789972d38
2 changed files with 8 additions and 14 deletions

View file

@ -27,6 +27,10 @@ from ..beancount_types import (
class MetaApproval(core._RequireLinksPostingMetadataHook): class MetaApproval(core._RequireLinksPostingMetadataHook):
CHECKED_METADATA = ['approval'] CHECKED_METADATA = ['approval']
SKIP_FLAGS = '!' SKIP_FLAGS = '!'
SKIP_TAX_IMPLICATIONS = frozenset([
'Bank-Transfer',
'Chargeback',
])
def __init__(self, config: configmod.Config) -> None: def __init__(self, config: configmod.Config) -> None:
self.payment_threshold = -config.payment_threshold() self.payment_threshold = -config.payment_threshold()
@ -48,5 +52,5 @@ class MetaApproval(core._RequireLinksPostingMetadataHook):
return ( return (
post.account.is_cash_equivalent() post.account.is_cash_equivalent()
and post.units.number < 0 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
) )

View file

@ -163,24 +163,14 @@ def test_approval_not_required_to_pay_credit_card(hook):
('Bank-Transfer', 'Assets:Savings'), ('Bank-Transfer', 'Assets:Savings'),
('Chargeback', 'Income:Donations'), ('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=[ txn = testutil.Transaction(postings=[
('Assets:Checking', -250, {'tax-implication': tax_implication}), ('Assets:Checking', -250, {'tax-implication': tax_implication}),
(other_acct, 250), (other_acct, 245),
('Expenses:BankingFees', 5),
]) ])
assert not list(hook.run(txn)) 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): def test_not_required_on_flagged(hook):
txn = testutil.Transaction(flag='!', postings=[ txn = testutil.Transaction(flag='!', postings=[
('Assets:Checking', -25), ('Assets:Checking', -25),