Changeset - 83e6e80bb89c
[Not reviewed]
0 2 0
Bradley Kuhn (bkuhn) - 3 years ago 2021-12-06 18:43:32
bkuhn@ebb.org
meta_payroll_type — US:PTO — distinguish between Earned and Taken

Metadata `payroll-type` will go on `Liabilities:Payable:Vacation` and
`Expenses:Payroll:Salary`, but we need to distinguish as to whether
the Payroll was earned or taken.

Later, `Liabilities:Payable:Vacation` should require a
`payroll-type` metadata of either `US:PTO:Taken` or `US:PTO:Earned`,
and the `CA:` equivalents.
2 files changed with 4 insertions and 2 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/plugin/meta_payroll_type.py
Show inline comments
...
 
@@ -54,46 +54,47 @@ class SalaryHook(_PayrollTypeHook):
 
    _tax_values = [
 
        'CA:Tax:EI',
 
        'CA:Tax:Income',
 
        'CA:Tax:PP',
 
        'US:IL:Tax:Income',
 
        'US:MA:Tax:Income',
 
        'US:NY:Tax:Income',
 
        'US:NY:Tax:NYC',
 
        'US:OR:Tax:Income',
 
        'US:OR:Tax:STT',
 
        'US:Tax:Income',
 
        'US:Tax:Medicare',
 
        'US:Tax:SocialSecurity',
 
    ]
 
    VALUES_ENUM = core.MetadataEnum(METADATA_KEY, [
 
        'CA:General',
 
        'CA:PTO',
 
        'US:403b:Employee',
 
        'US:403b:Match',
 
        'US:General',
 
        'US:MA:Disability:PFL',
 
        'US:MA:Disability:PML',
 
        'US:NY:Disability',
 
        'US:NY:Disability:PFL',
 
        'US:PTO',
 
        'US:PTO:Earned',
 
        'US:PTO:Taken',
 
        *_tax_values,
 
    ], {
 
        value.replace(':Tax:', ':Taxes:', 1): value
 
        for value in _tax_values
 
    })
 
    del _tax_values
 

	
 

	
 
class TaxHook(_PayrollTypeHook):
 
    ACCOUNT = 'Expenses:Payroll:Taxes'
 
    VALUES_ENUM = core.MetadataEnum(METADATA_KEY, [
 
        'CA:EI',
 
        'CA:PP',
 
        'US:IL:Unemployment',
 
        'US:MA:Health',
 
        'US:MA:Unemployment',
 
        'US:MA:WorkTrain',
 
        'US:Medicare',
 
        'US:OR:Unemployment',
 
        'US:SocialSecurity',
 
    ])
tests/test_meta_payroll_type.py
Show inline comments
...
 
@@ -21,49 +21,50 @@ class HookData(typing.NamedTuple):
 
    @classmethod
 
    def from_hook(cls, hook, *valid_values):
 
        return cls(hook.ACCOUNT, hook, set(valid_values), set())
 

	
 
    @classmethod
 
    def set_invalid_values(cls, datas):
 
        all_values = frozenset(v for d in datas for v in d.valid_values)
 
        for data in datas:
 
            data.invalid_values.update(all_values.difference(data.valid_values))
 

	
 

	
 
TEST_KEY = 'payroll-type'
 
HOOK_DATA = [
 
    HookData.from_hook(meta_payroll_type.HealthInsuranceHook,
 
                       'US:HRA:Fees', 'US:HRA:Usage', 'US:Premium:Main'),
 
    HookData.from_hook(meta_payroll_type.OtherBenefitsHook,
 
                       'US:403b:Fees', 'US:Education', 'US:ProfessionalMembership'),
 
    HookData.from_hook(
 
        meta_payroll_type.SalaryHook,
 
        'CA:Tax:EI',
 
        'US:NY:Tax:NYC',
 
        'US:Taxes:Medicare',
 
        'CA:General',
 
        'US:403b:Match',
 
        'US:PTO',
 
        'US:PTO:Earned',
 
        'US:PTO:Taken',
 
    ),
 
    HookData.from_hook(meta_payroll_type.TaxHook,
 
                       'CA:PP', 'US:IL:Unemployment', 'US:SocialSecurity'),
 
]
 
HookData.set_invalid_values(HOOK_DATA)
 

	
 
@pytest.fixture(scope='module')
 
def config():
 
    return testutil.TestConfig()
 

	
 
def norm_value(value):
 
    return value.replace(':Taxes:', ':Tax:', 1)
 

	
 
@pytest.mark.parametrize('hook_type,account,value', (
 
    (data.hook_type, data.account, value)
 
    for data in HOOK_DATA
 
    for value in data.valid_values
 
))
 
def test_valid_value_on_post(config, hook_type, account, value):
 
    txn = testutil.Transaction(postings=[
 
        (account, 55, {TEST_KEY: value}),
 
        ('Assets:Checking', -55),
 
    ])
 
    errors = list(hook_type(config).run(txn))
0 comments (0 inline, 0 general)