Changeset - 71f50a6cf864
[Not reviewed]
0 4 0
Brett Smith - 3 years ago 2020-12-29 17:20:53
brettcsmith@brettcsmith.org
data: Bugfix is_opening_balance_txn() for donations from equity. RT#13516

Opening balance transactions should only include opening equity
accounts and non-equity accounts. Reflect that in the test.
4 files changed with 21 insertions and 6 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/data.py
Show inline comments
...
 
@@ -684,13 +684,13 @@ def is_opening_balance_txn(txn: Transaction) -> bool:
 
    except KeyError:
 
        pass
 
    opening_equity = balance_of(txn, Account.is_opening_equity)
 
    if not opening_equity.currency:
 
        retval = False
 
    else:
 
        rest = balance_of(txn, lambda acct: not acct.is_opening_equity())
 
        if not rest.currency:
 
            retval = False
 
        else:
 
            retval = abs(opening_equity.number + rest.number) < decimal.Decimal('.01')
 
        rest = balance_of(txn, lambda acct: not acct.is_under(*EQUITY_ACCOUNTS))
 
        retval = (
 
            opening_equity.currency == rest.currency
 
            and abs(opening_equity.number + rest.number) < decimal.Decimal('.01')
 
        )
 
    _opening_balance_cache[key] = retval
 
    return retval
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.14.2',
 
    version='1.14.3',
 
    author='Software Freedom Conservancy',
 
    author_email='info@sfconservancy.org',
 
    license='GNU AGPLv3+',
 

	
 
    install_requires=[
 
        'babel>=2.6',  # Debian:python3-babel
tests/test_data_is_opening_balance_txn.py
Show inline comments
...
 
@@ -47,12 +47,14 @@ def test_opening_with_fx():
 
@pytest.mark.parametrize('acct1,acct2,number', [
 
    ('Assets:Receivable:Accounts', 'Income:Donations', 100),
 
    ('Expenses:Other', 'Liabilities:Payable:Accounts', 200),
 
    ('Expenses:Other', 'Equity:Retained:Costs', 300),
 
    # Release from restriction
 
    ('Equity:Funds:Unrestricted', 'Equity:Funds:Restricted', 400),
 
    # Donation from project fund
 
    ('Equity:Funds:Restricted', 'Income:Donations', 500),
 
])
 
def test_not_opening_balance(acct1, acct2, number):
 
    txn = testutil.Transaction(postings=[
 
        (acct1, number),
 
        (acct2, -number),
 
    ])
tests/test_meta_entity.py
Show inline comments
...
 
@@ -185,12 +185,25 @@ def test_invalid_payee_but_valid_metadata(hook, payee, src_value):
 
    txn = testutil.Transaction(**{'payee': payee, TEST_KEY: src_value}, postings=[
 
        ('Assets:Cash', -25),
 
        ('Expenses:Other', 25),
 
    ])
 
    assert not any(hook.run(txn))
 

	
 
def test_mixed_sources(hook):
 
    txn = testutil.Transaction(payee='Payee', postings=[
 
        ('Income:Donations', -5),
 
        ('Equity:Funds:Restricted', 5, {TEST_KEY: 'Entity'}),
 
    ])
 
    assert not any(hook.run(txn))
 
    assert txn.postings[-1].meta[TEST_KEY] == 'Entity'
 
    assert txn.meta[TEST_KEY] == 'Payee'
 
    try:
 
        assert txn.postings[0].meta[TEST_KEY] == 'Payee'
 
    except (KeyError, TypeError):
 
        pass
 

	
 
@pytest.mark.parametrize('account,required', [
 
    ('Assets:Bank:Checking', False),
 
    ('Assets:Cash', False),
 
    ('Assets:Receivable:Accounts', True),
 
    ('Assets:Receivable:Loans', True),
 
    ('Equity:OpeningBalances', False),
0 comments (0 inline, 0 general)