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
...
 
@@ -12,28 +12,31 @@
 
# GNU Affero General Public License for more details.
 
#
 
# You should have received a copy of the GNU Affero General Public License
 
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
 

	
 
from . import core
 
from .. import config as configmod
 
from .. import data
 
from .. import errors as errormod
 
from ..beancount_types import (
 
    MetaValueEnum,
 
    Transaction,
 
)
 

	
 
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:
 
        return bool(
 
            (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
 
        )
 

	
 
    def post_run(self, txn: Transaction, post: data.Posting) -> errormod.Iter:
 
        try:
 
            self._check_links(txn, post, 'receipt')
 
        except errormod.Error as receipt_error:
conservancy_beancount/plugin/meta_tax_implication.py
Show inline comments
...
 
@@ -14,19 +14,18 @@
 
# You should have received a copy of the GNU Affero General Public License
 
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
 

	
 
import decimal
 

	
 
from . import core
 
from .. import config as configmod
 
from .. import data
 
from ..beancount_types import (
 
    Transaction,
 
)
 

	
 
DEFAULT_STOP_AMOUNT = decimal.Decimal(0)
 

	
 
class MetaTaxImplication(core._NormalizePostingMetadataHook):
 
    VALUES_ENUM = core.MetadataEnum('tax-implication', [
 
        '1099',
 
        'Accountant-Advises-No-1099',
 
        'Bank-Transfer',
 
        'Foreign-Corporation',
...
 
@@ -42,12 +41,11 @@ class MetaTaxImplication(core._NormalizePostingMetadataHook):
 
        'USA-501c3',
 
        'USA-Corporation',
 
        'USA-LLC-No-1099',
 
        'W2',
 
    ])
 

	
 
    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
...
 
@@ -141,23 +141,28 @@ class Transaction:
 
        else:
 
            posting = arg
 
        self.postings.append(posting)
 

	
 

	
 
class TestConfig:
 
    def __init__(self,
 
    def __init__(self, *,
 
                 payment_threshold=0,
 
                 repo_path=None,
 
                 rt_client=None,
 
    ):
 
        self._payment_threshold = Decimal(payment_threshold)
 
        self.repo_path = test_path(repo_path)
 
        self._rt_client = rt_client
 
        if rt_client is None:
 
            self._rt_wrapper = None
 
        else:
 
            self._rt_wrapper = rtutil.RT(rt_client)
 

	
 
    def payment_threshold(self):
 
        return self._payment_threshold
 

	
 
    def repository_path(self):
 
        return self.repo_path
 

	
 
    def rt_client(self):
 
        return self._rt_client
 

	
0 comments (0 inline, 0 general)