diff --git a/conservancy_beancount/plugin/meta_tax_implication.py b/conservancy_beancount/plugin/meta_tax_implication.py index b14144d45ba7c581229e3a2544af19812ca3b91c..ce1ba87cfb0e2efde769d2d65799b84954b76286 100644 --- a/conservancy_beancount/plugin/meta_tax_implication.py +++ b/conservancy_beancount/plugin/meta_tax_implication.py @@ -19,13 +19,33 @@ 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) + 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): - VALUES_ENUM = core.MetadataEnum('tax-implication', [ - '1099', + _STDNAMES = [ + '1099-MISC-Other', + '1099-NEC', 'Bank-Transfer', 'Chargeback', 'Foreign-Corporation', @@ -38,7 +58,14 @@ class MetaTaxImplication(core._NormalizePostingMetadataHook): 'USA-501c3', 'USA-Corporation', '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 + # Sometimes we accrue a payment before we have determined the recipient's # tax status. SKIP_FLAGS = '!' diff --git a/setup.py b/setup.py index 53730ac124835bbf55b8f5129f3ab3b37e32b09c..fefae7df8bd4a80897882001781886d5c7734bd5 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup setup( name='conservancy_beancount', description="Plugin, library, and reports for reading Conservancy's books", - version='1.6.1', + version='1.6.2', author='Software Freedom Conservancy', author_email='info@sfconservancy.org', license='GNU AGPLv3+', diff --git a/tests/test_meta_tax_implication.py b/tests/test_meta_tax_implication.py index 8d490ca6e2ce1a18cd67c36ceda894fcaf88cb04..4c55f04ae2f6a45b2efda94a80c186e6ad6766fa 100644 --- a/tests/test_meta_tax_implication.py +++ b/tests/test_meta_tax_implication.py @@ -21,7 +21,11 @@ from . import testutil from conservancy_beancount.plugin import meta_tax_implication VALID_VALUES = { - '1099': '1099', + '1099': '1099-NEC', + '1099-NEC': '1099-NEC', + '1099nec': '1099-NEC', + '1099-MISC-Other': '1099-MISC-Other', + '1099misc-other': '1099-MISC-Other', 'Bank-Transfer': 'Bank-Transfer', 'Chargeback': 'Chargeback', 'Foreign-Corporation': 'Foreign-Corporation',