Changeset - 34090df23f06
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-03-05 18:44:36
brettcsmith@brettcsmith.org
expenseAllocation: Set default values by account.
2 files changed with 25 insertions and 0 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/plugin/meta_expense_allocation.py
Show inline comments
...
 
@@ -30,3 +30,11 @@ class MetaExpenseAllocation(core.PostingChecker):
 
    ACCOUNTS = ('Expenses:',)
 
    METADATA_KEY = 'expenseAllocation'
 
    VALUES_ENUM = ExpenseAllocations
 
    DEFAULT_VALUES = {
 
        'Expenses:Services:Accounting': VALUES_ENUM.administration,
 
        'Expenses:Services:Administration': VALUES_ENUM.administration,
 
        'Expenses:Services:Fundraising': VALUES_ENUM.fundraising,
 
    }
 

	
 
    def _default_value(self, txn, post):
 
        return self.DEFAULT_VALUES.get(post.account, self.VALUES_ENUM.program).value
tests/test_meta_expenseAllocation.py
Show inline comments
...
 
@@ -92,3 +92,20 @@ def test_non_expense_accounts_skipped(account):
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = checker.check(txn, txn.postings[0])
 
    assert not errors
 

	
 
@pytest.mark.parametrize('account,set_value', [
 
    ('Expenses:Services:Accounting', 'administration'),
 
    ('Expenses:Services:Administration', 'administration'),
 
    ('Expenses:Services:Advocacy', 'program'),
 
    ('Expenses:Services:Development', 'program'),
 
    ('Expenses:Services:Fundraising', 'fundraising'),
 
])
 
def test_default_values(account, set_value):
 
    txn = testutil.Transaction(postings=[
 
        ('Liabilites:CreditCard', -25),
 
        (account, 25),
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = checker.check(txn, txn.postings[-1])
 
    assert not errors
 
    assert txn.postings[-1].meta['expenseAllocation'] == set_value
0 comments (0 inline, 0 general)