"""meta_payroll_type - Validate payroll-type metadata"""
# Copyright © 2020 Bradley M. Kuhn, 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 datetime
from . import core
from .. import ranges
from .. import data
from .. import errors as errormod
from ..beancount_types import (
Transaction,
)
METADATA_KEY = 'payroll-type'
class _PayrollTypeHook(core._NormalizePostingMetadataHook):
ACCOUNT: str
VALUES_ENUM = core.MetadataEnum(METADATA_KEY, [])
TXN_DATE_RANGE = ranges.DateRange(
datetime.date(2020, 3, 1),
core.DEFAULT_STOP_DATE,
)
def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
return post.account.is_under(self.ACCOUNT) is not None
class HealthInsuranceHook(_PayrollTypeHook):
ACCOUNT = 'Expenses:Payroll:Benefits:HealthInsurance'
VALUES_ENUM = core.MetadataEnum(METADATA_KEY, [
'US:HRA:Fees',
'US:HRA:Usage',
'US:Premium:DentalVision',
'US:Premium:Main',
])
class OtherBenefitsHook(_PayrollTypeHook):
ACCOUNT = 'Expenses:Payroll:Benefits:Other'
VALUES_ENUM = core.MetadataEnum(METADATA_KEY, [
'US:403b:Fees',
'US:Education',
'US:ProfessionalMembership',
])
class SalaryHook(_PayrollTypeHook):
ACCOUNT = 'Expenses:Payroll:Salary'
_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',
*_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',
])