Changeset - f9411e0ffe79
[Not reviewed]
0 3 0
Brett Smith - 4 years ago 2020-06-22 20:34:06
brettcsmith@brettcsmith.org
meta_receipt: Not required on interest income. RT#11695.
3 files changed with 31 insertions and 1 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/plugin/meta_receipt.py
Show inline comments
...
 
@@ -33,12 +33,24 @@ class MetaReceipt(core._RequireLinksPostingMetadataHook):
 
    CHECKED_METADATA = ['receipt']
 
    SKIP_FLAGS = '!'
 

	
 
    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())
 
            and not post.account.is_under('Assets:PayPal')
 
            and abs(post.units.number) >= self.payment_threshold
 
        )
setup.py
Show inline comments
...
 
@@ -2,13 +2,13 @@
 

	
 
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+',
 

	
 
    install_requires=[
 
        'babel>=2.6',  # Debian:python3-babel
tests/test_meta_receipt.py
Show inline comments
...
 
@@ -341,12 +341,30 @@ def test_fallback_on_zero_amount_postings(hook, test_pair, other_acct, value):
 
        ('Income:Donations', '-.1'),
 
        ('Expenses:BankingFees', '.1'),
 
        (test_acct.name, 0, {meta_key: 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,
 
))
 
def test_not_required_on_opening(hook, test_acct, equity_acct):
 
    check(hook, test_acct, equity_acct, None)
0 comments (0 inline, 0 general)