diff --git a/conservancy_beancount/plugin/meta_expense_allocation.py b/conservancy_beancount/plugin/meta_expense_allocation.py index 1f09cce60e631d7ca0a13b015b20149427eaee8e..74ede4de04f706003062cf393e6fecd416581377 100644 --- a/conservancy_beancount/plugin/meta_expense_allocation.py +++ b/conservancy_beancount/plugin/meta_expense_allocation.py @@ -15,11 +15,14 @@ # along with this program. If not, see . from . import core +from .._typing import ( + MetaValueEnum, + Posting, + Transaction, +) -class MetaExpenseAllocation(core.PostingChecker): - ACCOUNTS = ('Expenses:',) - METADATA_KEY = 'expense-allocation' - VALUES_ENUM = core.MetadataEnum(METADATA_KEY, { +class MetaExpenseAllocation(core._NormalizePostingMetadataHook): + VALUES_ENUM = core.MetadataEnum('expense-allocation', { 'administration', 'fundraising', 'program', @@ -32,5 +35,8 @@ class MetaExpenseAllocation(core.PostingChecker): 'Expenses:Services:Fundraising': VALUES_ENUM['fundraising'], } - def _default_value(self, txn, post): + def _run_on_post(self, txn: Transaction, post: Posting) -> bool: + return post.account.startswith('Expenses:') + + def _default_value(self, txn: Transaction, post: Posting) -> MetaValueEnum: return self.DEFAULT_VALUES.get(post.account, 'program')