72 lines
2 KiB
Python
72 lines
2 KiB
Python
"""meta_tax_implication - Validate tax-implication metadata"""
|
|
# Copyright © 2020 Brett Smith
|
|
# License: AGPLv3-or-later WITH Beancount-Plugin-Additional-Permission-1.0
|
|
#
|
|
# Full copyright and licensing details can be found at toplevel file
|
|
# LICENSE.txt in the repository.
|
|
|
|
import decimal
|
|
|
|
from . import core
|
|
from .. import config as configmod
|
|
from .. import data
|
|
|
|
from typing import (
|
|
Iterator,
|
|
Optional,
|
|
Tuple,
|
|
)
|
|
from ..beancount_types import (
|
|
Transaction,
|
|
)
|
|
|
|
def _make_aliases(s: str, stdname: Optional[str]=None) -> Iterator[Tuple[str, str]]:
|
|
if stdname is None:
|
|
stdname = s
|
|
elif s != stdname:
|
|
yield (s, stdname)
|
|
yield (s.lower(), stdname)
|
|
title_s = s.title()
|
|
if s != title_s:
|
|
yield (title_s, stdname)
|
|
if s.startswith('1099-'):
|
|
yield from _make_aliases(f'1099{s[5:]}', stdname)
|
|
elif s.startswith('USA-'):
|
|
yield from _make_aliases(f'US-{s[4:]}', stdname)
|
|
if s.endswith('-Corporation'):
|
|
yield from _make_aliases(f'{s[:-12]}-Corp', stdname)
|
|
|
|
class MetaTaxImplication(core._NormalizePostingMetadataHook):
|
|
_STDNAMES = [
|
|
'1099-MISC-Other',
|
|
'1099-NEC',
|
|
'Bank-Transfer',
|
|
'Chargeback',
|
|
'Foreign-Corporation',
|
|
'Foreign-Grantee',
|
|
'Foreign-Individual-Contractor',
|
|
'Loan',
|
|
'Refund',
|
|
'Reimbursement',
|
|
'Retirement-Pretax',
|
|
'Tax-Payment',
|
|
'USA-501c3',
|
|
'USA-Corporation',
|
|
'USA-Grantee',
|
|
'W2',
|
|
]
|
|
_ALIASES = dict(
|
|
alias for value in _STDNAMES for alias in _make_aliases(value)
|
|
)
|
|
_ALIASES['1099'] = '1099-NEC'
|
|
VALUES_ENUM = core.MetadataEnum('tax-implication', _STDNAMES, _ALIASES)
|
|
del _STDNAMES, _ALIASES
|
|
|
|
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
|
|
)
|