Changeset - 30d371278aeb
[Not reviewed]
0 3 0
Brett Smith - 4 years ago 2020-03-29 14:30:54
brettcsmith@brettcsmith.org
plugin: Refactor hooks to use new payment-related methods.
3 files changed with 17 insertions and 11 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/plugin/meta_receipt.py
Show inline comments
...
 
@@ -17,2 +17,3 @@
 
from . import core
 
from .. import config as configmod
 
from .. import data
...
 
@@ -25,5 +26,7 @@ from ..beancount_types import (
 
class MetaReceipt(core._RequireLinksPostingMetadataHook):
 
    DEFAULT_STOP_AMOUNT = 0
 
    METADATA_KEY = 'receipt'
 

	
 
    def __init__(self, config: configmod.Config) -> None:
 
        self.payment_threshold = -abs(config.payment_threshold())
 

	
 
    def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
...
 
@@ -31,4 +34,4 @@ class MetaReceipt(core._RequireLinksPostingMetadataHook):
 
            (post.account.is_real_asset() or post.account.is_under('Liabilities'))
 
            and post.units.number
 
            and post.units.number < self.DEFAULT_STOP_AMOUNT
 
            and post.units.number is not None
 
            and post.units.number < self.payment_threshold
 
        )
conservancy_beancount/plugin/meta_tax_implication.py
Show inline comments
...
 
@@ -19,2 +19,3 @@ import decimal
 
from . import core
 
from .. import config as configmod
 
from .. import data
...
 
@@ -24,4 +25,2 @@ from ..beancount_types import (
 

	
 
DEFAULT_STOP_AMOUNT = decimal.Decimal(0)
 

	
 
class MetaTaxImplication(core._NormalizePostingMetadataHook):
...
 
@@ -47,7 +46,6 @@ class MetaTaxImplication(core._NormalizePostingMetadataHook):
 

	
 
    def __init__(self, config: configmod.Config) -> None:
 
        self.payment_threshold = config.payment_threshold()
 

	
 
    def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
 
        return bool(
 
            post.account.is_real_asset()
 
            and post.units.number
 
            and post.units.number < DEFAULT_STOP_AMOUNT
 
        )
 
        return post.is_payment(self.payment_threshold)
tests/testutil.py
Show inline comments
...
 
@@ -146,3 +146,4 @@ class Transaction:
 
class TestConfig:
 
    def __init__(self,
 
    def __init__(self, *,
 
                 payment_threshold=0,
 
                 repo_path=None,
...
 
@@ -150,2 +151,3 @@ class TestConfig:
 
    ):
 
        self._payment_threshold = Decimal(payment_threshold)
 
        self.repo_path = test_path(repo_path)
...
 
@@ -157,2 +159,5 @@ class TestConfig:
 

	
 
    def payment_threshold(self):
 
        return self._payment_threshold
 

	
 
    def repository_path(self):
0 comments (0 inline, 0 general)