diff --git a/conservancy_beancount/plugin/meta_approval.py b/conservancy_beancount/plugin/meta_approval.py index ce1dbc1ef9f432fdc0d888e7270016cd56980dac..d9704eb7990c2ea6c73931f356b88b8247561b1f 100644 --- a/conservancy_beancount/plugin/meta_approval.py +++ b/conservancy_beancount/plugin/meta_approval.py @@ -28,7 +28,7 @@ class MetaApproval(core._RequireLinksPostingMetadataHook): CHECKED_METADATA = ['approval'] def __init__(self, config: configmod.Config) -> None: - self.payment_threshold = config.payment_threshold() + self.payment_threshold = -config.payment_threshold() def _run_on_txn(self, txn: Transaction) -> bool: if not super()._run_on_txn(txn): @@ -36,14 +36,12 @@ class MetaApproval(core._RequireLinksPostingMetadataHook): # approval is required when funds leave a cash equivalent asset, # UNLESS that transaction is a transfer to another asset, # or paying off a credit card. - # debits_sum keeps a running tally of how much is moving in each - # direction, and we'll return True if it ends up over the payment - # threshold. - debits_sum = decimal.Decimal(0) - for post in data.iter_postings(txn): - if post.account.is_cash_equivalent() or post.account.is_credit_card(): - debits_sum -= post.units.number or 0 - return debits_sum > self.payment_threshold + balance = data.balance_of( + txn, + data.Account.is_cash_equivalent, + data.Account.is_credit_card, + ) + return balance is None or balance < self.payment_threshold def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool: return post.account.is_cash_equivalent() and not post.is_credit(0)