]> git.walde.dev - beanbeanbean/commitdiff
Add option to set require_docs for txns &/or bals
authorDustin Walde <redacted>
Sun, 12 Nov 2023 06:07:44 +0000 (22:07 -0800)
committerDustin Walde <redacted>
Sun, 12 Nov 2023 06:10:46 +0000 (22:10 -0800)
src/beanbeanbean/require_documents.py

index c9cb324acdc5a0e6ba8df04d9915f95d80d5452f..fe66fd18ac91ce99309507559c1be6536a48be2c 100644 (file)
@@ -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