From: Dustin Walde Date: Sun, 12 Nov 2023 06:07:44 +0000 (-0800) Subject: Add option to set require_docs for txns &/or bals X-Git-Url: https://git.walde.dev/?a=commitdiff_plain;h=7ca72954c1effeb8aeb086d78bc381a9fce46b84;p=beanbeanbean Add option to set require_docs for txns &/or bals --- diff --git a/src/beanbeanbean/require_documents.py b/src/beanbeanbean/require_documents.py index c9cb324..fe66fd1 100644 --- a/src/beanbeanbean/require_documents.py +++ b/src/beanbeanbean/require_documents.py @@ -9,15 +9,21 @@ __plugins__ = ('require_documents',) def require_documents(entries: Entries, options_map, config_string=""): - print(options_map) errors = [] + require_transactions = True + require_balances = True + if 'require_documents' in options_map: + types = options_map['require_documents'].lower().split(",") + require_transactions = "transaction" in types or "transactions" in types + require_balances = "balance" in types or "balances" in types for i, entry in enumerate(entries): - if type(entry) is Transaction or type(entry) is Balance: + if (type(entry) is Transaction and require_transactions) \ + or (type(entry) is Balance and require_balances): 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.")) + errors.append(make_error(entry, "{} missing document.".format(type(entry).__name__))) return entries, errors