
It makes sense to let the bookkeeper skip validations in situations where the metadata requires information that might not be available when entered. It does not make sense to skip validations that *must* be available and affect the structure of the books, like project and entity. This commit ensures every plugin hook has a test for flagged transactions, even for hooks that currently have the desired behavior where no code changes were required for the test to pass.
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
"""meta_tax_implication - Validate tax-implication metadata"""
|
|
# Copyright © 2020 Brett Smith
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# 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/>.
|
|
|
|
import decimal
|
|
|
|
from . import core
|
|
from .. import config as configmod
|
|
from .. import data
|
|
from ..beancount_types import (
|
|
Transaction,
|
|
)
|
|
|
|
class MetaTaxImplication(core._NormalizePostingMetadataHook):
|
|
VALUES_ENUM = core.MetadataEnum('tax-implication', [
|
|
'1099',
|
|
'Bank-Transfer',
|
|
'Chargeback',
|
|
'Foreign-Corporation',
|
|
'Foreign-Individual-Contractor',
|
|
'Loan',
|
|
'Refund',
|
|
'Reimbursement',
|
|
'Retirement-Pretax',
|
|
'Tax-Payment',
|
|
'USA-501c3',
|
|
'USA-Corporation',
|
|
'W2',
|
|
])
|
|
# Sometimes we accrue a payment before we have determined the recipient's
|
|
# tax status.
|
|
SKIP_FLAGS = '!'
|
|
|
|
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 (
|
|
post.account.is_cash_equivalent()
|
|
and post.units.number < self.payment_threshold
|
|
)
|