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.
This commit is contained in:
Brett Smith 2020-12-29 12:20:53 -05:00
parent 7abc01b1ac
commit 71f50a6cf8
4 changed files with 21 additions and 6 deletions

View file

@ -687,10 +687,10 @@ def is_opening_balance_txn(txn: Transaction) -> bool:
if not opening_equity.currency: if not opening_equity.currency:
retval = False retval = False
else: else:
rest = balance_of(txn, lambda acct: not acct.is_opening_equity()) rest = balance_of(txn, lambda acct: not acct.is_under(*EQUITY_ACCOUNTS))
if not rest.currency: retval = (
retval = False opening_equity.currency == rest.currency
else: and abs(opening_equity.number + rest.number) < decimal.Decimal('.01')
retval = abs(opening_equity.number + rest.number) < decimal.Decimal('.01') )
_opening_balance_cache[key] = retval _opening_balance_cache[key] = retval
return retval return retval

View file

@ -5,7 +5,7 @@ from setuptools import setup
setup( setup(
name='conservancy_beancount', name='conservancy_beancount',
description="Plugin, library, and reports for reading Conservancy's books", description="Plugin, library, and reports for reading Conservancy's books",
version='1.14.2', version='1.14.3',
author='Software Freedom Conservancy', author='Software Freedom Conservancy',
author_email='info@sfconservancy.org', author_email='info@sfconservancy.org',
license='GNU AGPLv3+', license='GNU AGPLv3+',

View file

@ -50,6 +50,8 @@ def test_opening_with_fx():
('Expenses:Other', 'Equity:Retained:Costs', 300), ('Expenses:Other', 'Equity:Retained:Costs', 300),
# Release from restriction # Release from restriction
('Equity:Funds:Unrestricted', 'Equity:Funds:Restricted', 400), ('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): def test_not_opening_balance(acct1, acct2, number):
txn = testutil.Transaction(postings=[ txn = testutil.Transaction(postings=[

View file

@ -188,6 +188,19 @@ def test_invalid_payee_but_valid_metadata(hook, payee, src_value):
]) ])
assert not any(hook.run(txn)) 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', [ @pytest.mark.parametrize('account,required', [
('Assets:Bank:Checking', False), ('Assets:Bank:Checking', False),
('Assets:Cash', False), ('Assets:Cash', False),