]> git.walde.dev - beanbeanbean/commitdiff
Add require_documents plugin
authorDustin Walde <redacted>
Thu, 9 Nov 2023 18:51:07 +0000 (10:51 -0800)
committerDustin Walde <redacted>
Thu, 9 Nov 2023 18:51:07 +0000 (10:51 -0800)
Basic metadata check for Transactions and Balances

src/beanbeanbean/require_documents.py [new file with mode: 0644]

diff --git a/src/beanbeanbean/require_documents.py b/src/beanbeanbean/require_documents.py
new file mode 100644 (file)
index 0000000..c9cb324
--- /dev/null
@@ -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
+