conservancy_beancount/conservancy_beancount/plugin/meta_expense_allocation.py
Brett Smith b2ef561c85 data: Introduce Posting class.
Our version of Posting is interface-compatible with Beancount's,
but makes stronger guarantees about the data types for our
higher-level code to rely on.
2020-03-18 07:48:08 -04:00

42 lines
1.6 KiB
Python

"""meta_expense_allocation - Validate expense-allocation metadata"""
# Copyright © 2020 Brett Smith
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from . import core
from .. import data
from ..beancount_types import (
MetaValueEnum,
Transaction,
)
class MetaExpenseAllocation(core._NormalizePostingMetadataHook):
VALUES_ENUM = core.MetadataEnum('expense-allocation', {
'administration',
'fundraising',
'program',
}, {
'admin': 'administration',
})
DEFAULT_VALUES = {
'Expenses:Services:Accounting': VALUES_ENUM['administration'],
'Expenses:Services:Administration': VALUES_ENUM['administration'],
'Expenses:Services:Fundraising': VALUES_ENUM['fundraising'],
}
def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
return post.account.startswith('Expenses:')
def _default_value(self, txn: Transaction, post: data.Posting) -> MetaValueEnum:
return self.DEFAULT_VALUES.get(post.account, 'program')