diff --git a/conservancy_beancount/plugin/meta_expense_allocation.py b/conservancy_beancount/plugin/meta_expense_allocation.py index a81a960..e1e732e 100644 --- a/conservancy_beancount/plugin/meta_expense_allocation.py +++ b/conservancy_beancount/plugin/meta_expense_allocation.py @@ -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 diff --git a/tests/test_meta_expenseAllocation.py b/tests/test_meta_expenseAllocation.py index 9592ba1..34d9dd8 100644 --- a/tests/test_meta_expenseAllocation.py +++ b/tests/test_meta_expenseAllocation.py @@ -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