From: Dustin Walde Date: Thu, 9 Nov 2023 18:51:07 +0000 (-0800) Subject: Add require_documents plugin X-Git-Url: https://git.walde.dev/?a=commitdiff_plain;h=27accd7c1bea8a4a362744273ecd564b3b6d73c9;p=beanbeanbean Add require_documents plugin Basic metadata check for Transactions and Balances --- diff --git a/src/beanbeanbean/require_documents.py b/src/beanbeanbean/require_documents.py new file mode 100644 index 0000000..c9cb324 --- /dev/null +++ b/src/beanbeanbean/require_documents.py @@ -0,0 +1,23 @@ +from beancount.core.data import ( + Entries, + Balance, + Transaction, +) +from .utils import flag, make_error + +__plugins__ = ('require_documents',) + + +def require_documents(entries: Entries, options_map, config_string=""): + print(options_map) + errors = [] + + for i, entry in enumerate(entries): + if type(entry) is Transaction or type(entry) is Balance: + if not 'document' in entry.meta and not 'no-document' in entry.meta: + if type(entry) is Transaction: + entries[i] = flag(entry) + errors.append(make_error(entry, "Missing document.")) + + return entries, errors +