expenseAllocation: Set default values by account.

This commit is contained in:
Brett Smith 2020-03-05 13:44:36 -05:00
parent a1ec25a33d
commit 34090df23f
2 changed files with 25 additions and 0 deletions

View file

@ -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

View file

@ -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