From d7f17b334a952f2bd50395e58917c5f3f9dd4b9a Mon Sep 17 00:00:00 2001 From: Kristen Marie Kulha Date: Thu, 3 May 2018 15:37:19 -0700 Subject: [PATCH 01/10] Initial commit of North Carolina Payroll `l10n_us_nc_hr_payroll` for 11.0 --- l10n_us_nc_hr_payroll/__init__.py | 1 + l10n_us_nc_hr_payroll/__manifest__.py | 27 ++ l10n_us_nc_hr_payroll/data/base.xml | 46 +++ l10n_us_nc_hr_payroll/data/final.xml | 19 ++ l10n_us_nc_hr_payroll/data/rules_2018.xml | 107 ++++++ l10n_us_nc_hr_payroll/hr_payroll.py | 33 ++ l10n_us_nc_hr_payroll/hr_payroll_view.xml | 35 ++ l10n_us_nc_hr_payroll/tests/__init__.py | 1 + .../tests/test_us_nc_payslip_2018.py | 322 ++++++++++++++++++ 9 files changed, 591 insertions(+) create mode 100755 l10n_us_nc_hr_payroll/__init__.py create mode 100755 l10n_us_nc_hr_payroll/__manifest__.py create mode 100755 l10n_us_nc_hr_payroll/data/base.xml create mode 100755 l10n_us_nc_hr_payroll/data/final.xml create mode 100755 l10n_us_nc_hr_payroll/data/rules_2018.xml create mode 100755 l10n_us_nc_hr_payroll/hr_payroll.py create mode 100755 l10n_us_nc_hr_payroll/hr_payroll_view.xml create mode 100755 l10n_us_nc_hr_payroll/tests/__init__.py create mode 100755 l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py diff --git a/l10n_us_nc_hr_payroll/__init__.py b/l10n_us_nc_hr_payroll/__init__.py new file mode 100755 index 00000000..e99aa24a --- /dev/null +++ b/l10n_us_nc_hr_payroll/__init__.py @@ -0,0 +1 @@ +from . import hr_payroll diff --git a/l10n_us_nc_hr_payroll/__manifest__.py b/l10n_us_nc_hr_payroll/__manifest__.py new file mode 100755 index 00000000..17df0ab6 --- /dev/null +++ b/l10n_us_nc_hr_payroll/__manifest__.py @@ -0,0 +1,27 @@ +{ + 'name': 'USA - North Carolina - Payroll', + 'author': 'Hibou Corp. ', + 'license': 'AGPL-3', + 'category': 'Localization', + 'depends': ['l10n_us_hr_payroll'], + 'version': '11.0.2018.0.0', + 'description': """ +USA::North Carolina Payroll Rules. +================================== + +* Contribution register and partner for North Carolina Department of Taxaction - Unemployment +* Contribution register and partner for North Carolina Department of Taxaction - Income Tax Withholding +* Contract level North Carolina Exemptions +* Company level North Carolina Unemployment Rate + """, + + 'auto_install': False, + 'website': 'https://hibou.io/', + 'data': [ + 'hr_payroll_view.xml', + 'data/base.xml', + 'data/rules_2018.xml', + 'data/final.xml', + ], + 'installable': True +} diff --git a/l10n_us_nc_hr_payroll/data/base.xml b/l10n_us_nc_hr_payroll/data/base.xml new file mode 100755 index 00000000..5640ec00 --- /dev/null +++ b/l10n_us_nc_hr_payroll/data/base.xml @@ -0,0 +1,46 @@ + + + + + + North Carolina Division of Unemployment Security - Unemployment Tax + 1 + + + + North Carolina Department of Revenue - Income Tax Withholding + 1 + + + + North Carolina Unemployment + North Carolina Division of Unemployment Security - Unemployment + + + + North Carolina Income Tax Withholding + North Carolina Department of Revenue - Income Tax Withholding + + + + + + + North Carolina Unemployment - Wages + NC_UNEMP_WAGES + + + + North Carolina Unemployment + NC_UNEMP + + + + + North Carolina Income Withholding + NC_INC_WITHHOLD + + + + + diff --git a/l10n_us_nc_hr_payroll/data/final.xml b/l10n_us_nc_hr_payroll/data/final.xml new file mode 100755 index 00000000..d8086c80 --- /dev/null +++ b/l10n_us_nc_hr_payroll/data/final.xml @@ -0,0 +1,19 @@ + + + + + + + US_NC_EMP + USA North Carolina Employee + + + + + + + diff --git a/l10n_us_nc_hr_payroll/data/rules_2018.xml b/l10n_us_nc_hr_payroll/data/rules_2018.xml new file mode 100755 index 00000000..cacad79a --- /dev/null +++ b/l10n_us_nc_hr_payroll/data/rules_2018.xml @@ -0,0 +1,107 @@ + + + + + + + + + North Carolina Unemployment - Wages (2018) + NC_UNEMP_WAGES_2018 + python + result = (payslip.date_to[:4] == '2018') + code + +ytd = payslip.sum('NC_UNEMP_WAGES_2018', '2018-01-01', '2019-01-01') +ytd += contract.external_wages +remaining = 7000.0 - ytd +if remaining <= 0.0: + result = 0 +elif remaining < categories.GROSS: + result = remaining +else: + result = categories.GROSS + + + + + + + + North Carolina Unemployment (2018) + NC_UNEMP_2018 + python + result = (payslip.date_to[:4] == '2018') + code + +result_rate = -contract.nc_unemp_rate(2018) +result = categories.NC_UNEMP_WAGES + +# result_rate of 0 implies 100% due to bug +if result_rate == 0.0: + result = 0.0 + + + + + + + + + North Carolina Income Withholding + NC_INC_WITHHOLD_2018 + python + result = (payslip.date_to[:4] == '2018') + code + +wages = categories.GROSS +exemptions = contract.nc_nc4_allowances +schedule_pay = contract.schedule_pay +val = 0.00 + + +# PST -> Portion of standard deduction +PST = 0.0 +allowance_multiplier = 0.0 +if 'weekly' == schedule_pay: + allowance_multiplier = 48.08 + if contract.nc_nc4_filing_status == 'head_household': + PST = 269.23 + else: + PST = 168.27 +elif 'bi-weekly' == schedule_pay: + allowance_multiplier = 96.15 + if contract.nc_nc4_filing_status == 'head_household': + PST = 538.46 + else: + PST = 336.54 +elif 'semi-monthly' == schedule_pay: + allowance_multiplier = 104.17 + if contract.nc_nc4_filing_status == 'head_household': + PST = 583.33 + else: + PST = 364.58 +elif 'monthly' == schedule_pay: + allowance_multiplier = 208.33 + if contract.nc_nc4_filing_status == 'head_household': + PST = 1166.67 + else: + PST = 729.17 + +else: + raise Exception('Invalid schedule_pay="' + schedule_pay + '" for NC Income Withholding calculation') + +# Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf +if contract.nc_nc4_filing_status == 'exempt': + result = 0 +else: + if contract.w4_is_nonresident_alien: + result = round(((wages - (PST + (allowance_multiplier * exemptions))) * 0.05599) - contract.nc_nc4_additional_wh) + else: + result = round((wages - (PST + (allowance_multiplier * exemptions))) * 0.05599) + + + + + + diff --git a/l10n_us_nc_hr_payroll/hr_payroll.py b/l10n_us_nc_hr_payroll/hr_payroll.py new file mode 100755 index 00000000..8a0143bf --- /dev/null +++ b/l10n_us_nc_hr_payroll/hr_payroll.py @@ -0,0 +1,33 @@ +from odoo import models, fields, api + + +class USNCHrContract(models.Model): + _inherit = 'hr.contract' + + nc_nc4_allowances = fields.Integer(string='North Carolina NC-4 Allowances', default=0) + nc_nc4_filing_status = fields.Selection([ + ('exempt', 'Exempt'), + ('single', 'Single'), + ('married', 'Married'), + ('surviving_spouse', 'Surviving Spouse'), + ('head_household', 'Head of Household') + ], string='NC Filing Status', default='single') + nc_nc4_additional_wh = fields.Float(string="Additional Witholding", default=0.0) + + @api.multi + def nc_unemp_rate(self, year): + self.ensure_one() + if self.futa_type == self.FUTA_TYPE_BASIC: + return 0.0 + + if hasattr(self.employee_id.company_id, 'nc_unemp_rate_' + str(year)): + return self.employee_id.company_id['nc_unemp_rate_' + str(year)] + + raise NotImplemented('Year (' + str(year) + ') Not implemented for US North Carolina.') + + +class NCCompany(models.Model): + _inherit = 'res.company' + + # Unemployment rate provided by Katherine + nc_unemp_rate_2018 = fields.Float(string="North Carolina Unemployment Rate 2018", default=0.06) diff --git a/l10n_us_nc_hr_payroll/hr_payroll_view.xml b/l10n_us_nc_hr_payroll/hr_payroll_view.xml new file mode 100755 index 00000000..f8a454a2 --- /dev/null +++ b/l10n_us_nc_hr_payroll/hr_payroll_view.xml @@ -0,0 +1,35 @@ + + + + + res.company.form + res.company + 64 + + + + + + + + + + + hr.contract.form.inherit + hr.contract + 128 + + + + + + + + + + + + + + + diff --git a/l10n_us_nc_hr_payroll/tests/__init__.py b/l10n_us_nc_hr_payroll/tests/__init__.py new file mode 100755 index 00000000..5e31343d --- /dev/null +++ b/l10n_us_nc_hr_payroll/tests/__init__.py @@ -0,0 +1 @@ +from . import test_us_nc_payslip_2018 diff --git a/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py b/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py new file mode 100755 index 00000000..87fde82b --- /dev/null +++ b/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py @@ -0,0 +1,322 @@ +from odoo.addons.l10n_us_hr_payroll.tests.test_us_payslip import TestUsPayslip, process_payslip +from odoo.addons.l10n_us_hr_payroll.l10n_us_hr_payroll import USHrContract + + +class TestUsNCPayslip(TestUsPayslip): + ### + # Taxes and Rates + ### + NC_UNEMP_MAX_WAGE = 7000.0 + + + def test_2018_taxes_weekly(self): + salary = 5000.0 + schedule_pay = 'weekly' + # allowance_multiplier and Portion of Standard Deduction for weekly + allowance_multiplier = 48.08 + PST = 168.27 + + exemption = 1 + # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf + + wh = round((salary - (PST + (allowance_multiplier * exemption))) * 0.05599) + + employee = self._createEmployee() + employee.company_id.nc_unemp_rate_2018 = 0.06 + + contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + contract.nc_nc4_allowances = exemption + + self.assertEqual(contract.schedule_pay, 'weekly') + + # tax rates + nc_unemp = contract.nc_unemp_rate(2018) / -100.0 + + + self._log('2018 North Carolina tax first payslip weekly:') + payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) + self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) + self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_nc_unemp_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2*salary < salary) \ + else salary + + self._log('2018 North Carolina tax second payslip weekly:') + payslip = self._createPayslip(employee, '2018-02-01', '2018-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) + self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) + + def test_2018_taxes_with_external_weekly(self): + salary = 5000.0 + external_wages = 7000.0 + + schedule_pay = 'weekly' + + employee = self._createEmployee() + employee.company_id.nc_unemp_rate_2018 = 0.06 + + contract = self._createContract(employee, salary, external_wages=external_wages, + struct_id=self.ref('l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + + # tax rates + nc_unemp = contract.nc_unemp_rate(2018) / -100.0 + + self._log('2018 NorthCarolina_external tax first payslip weekly:') + payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], self.NC_UNEMP_MAX_WAGE - external_wages) + self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) + + def test_2018_taxes_with_state_exempt_weekly(self): + salary = 5000.0 + external_wages = 6000.0 + schedule_pay = 'weekly' + + employee = self._createEmployee() + employee.company_id.nc_unemp_rate_2018 = 0.06 + + contract = self._createContract(employee, salary, external_wages=external_wages, struct_id=self.ref( + 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), futa_type=USHrContract.FUTA_TYPE_BASIC, schedule_pay=schedule_pay) + + # tax rates + nc_unemp = contract.nc_unemp_rate(2018) / -100.0 + + self.assertPayrollEqual(nc_unemp, 0.0) + + self._log('2018 North Carolina exempt tax first payslip weekly:') + payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], self.NC_UNEMP_MAX_WAGE - external_wages) + self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) + + def test_2018_taxes_biweekly(self): + salary = 5000.0 + schedule_pay = 'bi-weekly' + # allowance_multiplier and Portion of Standard Deduction for weekly + allowance_multiplier = 96.15 + PST = 336.54 + + exceptions = 2 + # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf + + wh = round((salary - (PST + (allowance_multiplier * exceptions))) * 0.05599) + + employee = self._createEmployee() + employee.company_id.nc_unemp_rate_2018 = 0.06 + + contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + contract.nc_nc4_allowances = exceptions + + self.assertEqual(contract.schedule_pay, 'bi-weekly') + + # tax rates + nc_unemp = contract.nc_unemp_rate(2018) / -100.0 + + + self._log('2018 North Carolina tax first payslip bi-weekly:') + payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) + self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) + self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_nc_unemp_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2*salary < salary) \ + else salary + + self._log('2018 North Carolina tax second payslip bi-weekly:') + payslip = self._createPayslip(employee, '2018-02-01', '2018-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) + self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) + + def test_2018_taxes_semimonthly(self): + salary = 4000.0 + schedule_pay = 'semi-monthly' + nc_nc4_filing_status = 'head_household' + # allowance_multiplier and Portion of Standard Deduction for weekly + allowance_multiplier = 104.17 + PST = 583.33 + + exceptions = 1 + # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf + + wh = round((salary - (PST + (allowance_multiplier * exceptions))) * 0.05599) + + employee = self._createEmployee() + employee.company_id.nc_unemp_rate_2018 = 0.06 + + contract = self._createContract(employee, salary, struct_id=self.ref( + 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + contract.nc_nc4_allowances = exceptions + contract.nc_nc4_filing_status = nc_nc4_filing_status + + self.assertEqual(contract.schedule_pay, 'semi-monthly') + + # tax rates + nc_unemp = contract.nc_unemp_rate(2018) / -100.0 + + self._log('2018 North Carolina tax first payslip:') + payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) + self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) + self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_nc_unemp_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ + else salary + + self._log('2018 North Carolina tax second payslip:') + payslip = self._createPayslip(employee, '2018-02-01', '2018-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) + self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) + + def test_2018_taxes_monthly(self): + self.debug = True + salary = 4000.0 + schedule_pay = 'monthly' + # allowance_multiplier and Portion of Standard Deduction for weekly + allowance_multiplier = 208.33 + PST = 729.17 + + exceptions = 1 + # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf + + wh = round((salary - (PST + (allowance_multiplier * exceptions))) * 0.05599) + + employee = self._createEmployee() + employee.company_id.nc_unemp_rate_2018 = 0.06 + + contract = self._createContract(employee, salary, struct_id=self.ref( + 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + contract.nc_nc4_allowances = exceptions + + self.assertEqual(contract.schedule_pay, 'monthly') + + # tax rates + nc_unemp = contract.nc_unemp_rate(2018) / -100.0 + + self._log('2018 North Carolina tax first payslip:') + payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) + self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) + self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_nc_unemp_wages = self.NC_UNEMP_MAX_WAGE - salary if ( + self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ + else salary + + self._log('2018 North Carolina tax second payslip:') + payslip = self._createPayslip(employee, '2018-02-01', '2018-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) + self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) + + def test_tax_exempt(self): + salary = 4000.0 + wh = 0 + schedule_pay = 'weekly' + excemptions = 1 + + employee = self._createEmployee() + employee.company_id.nc_unemp_rate_2018 = 0.06 + + contract = self._createContract(employee, salary, struct_id=self.ref( + 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + contract.nc_nc4_allowances = excemptions + contract.nc_nc4_filing_status = 'exempt' + + self.assertEqual(contract.schedule_pay, 'weekly') + + # tax rates + nc_unemp = contract.nc_unemp_rate(2018) / -100.0 + + + self._log('2018 North Carolina tax first payslip:') + payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) + self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) + self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_nc_unemp_wages = self.NC_UNEMP_MAX_WAGE - salary if ( + self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ + else salary + + self._log('2018 North Carolina tax second payslip:') + payslip = self._createPayslip(employee, '2018-02-01', '2018-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) + self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) From 5738aada30a5712cde0674307ff779d4d1f25485 Mon Sep 17 00:00:00 2001 From: Kristen Marie Kulha Date: Fri, 4 May 2018 09:16:44 -0700 Subject: [PATCH 02/10] Fix Additional Withholding and add a warning for form NC-4 NRA --- l10n_us_nc_hr_payroll/data/rules_2018.xml | 8 +- l10n_us_nc_hr_payroll/hr_payroll.py | 4 +- .../tests/test_us_nc_payslip_2018.py | 81 ++++++++++++++++--- 3 files changed, 76 insertions(+), 17 deletions(-) diff --git a/l10n_us_nc_hr_payroll/data/rules_2018.xml b/l10n_us_nc_hr_payroll/data/rules_2018.xml index cacad79a..58e1f83a 100755 --- a/l10n_us_nc_hr_payroll/data/rules_2018.xml +++ b/l10n_us_nc_hr_payroll/data/rules_2018.xml @@ -55,7 +55,7 @@ if result_rate == 0.0: code wages = categories.GROSS -exemptions = contract.nc_nc4_allowances +allowances = contract.nc_nc4_allowances schedule_pay = contract.schedule_pay val = 0.00 @@ -95,10 +95,8 @@ else: if contract.nc_nc4_filing_status == 'exempt': result = 0 else: - if contract.w4_is_nonresident_alien: - result = round(((wages - (PST + (allowance_multiplier * exemptions))) * 0.05599) - contract.nc_nc4_additional_wh) - else: - result = round((wages - (PST + (allowance_multiplier * exemptions))) * 0.05599) + result = -round(((wages - (PST + (allowance_multiplier * allowances))) * 0.05599) + contract.nc_nc4_additional_wh) + diff --git a/l10n_us_nc_hr_payroll/hr_payroll.py b/l10n_us_nc_hr_payroll/hr_payroll.py index 8a0143bf..a4eb8572 100755 --- a/l10n_us_nc_hr_payroll/hr_payroll.py +++ b/l10n_us_nc_hr_payroll/hr_payroll.py @@ -12,7 +12,9 @@ class USNCHrContract(models.Model): ('surviving_spouse', 'Surviving Spouse'), ('head_household', 'Head of Household') ], string='NC Filing Status', default='single') - nc_nc4_additional_wh = fields.Float(string="Additional Witholding", default=0.0) + nc_nc4_additional_wh = fields.Float(string="Additional Witholding", default=0.0, + help="If you are filling out NC-4 NRA, this would be box 4; " \ + "otherwise box 2.") @api.multi def nc_unemp_rate(self, year): diff --git a/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py b/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py index 87fde82b..249acc27 100755 --- a/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py +++ b/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py @@ -19,7 +19,7 @@ class TestUsNCPayslip(TestUsPayslip): exemption = 1 # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf - wh = round((salary - (PST + (allowance_multiplier * exemption))) * 0.05599) + wh = -round((salary - (PST + (allowance_multiplier * exemption))) * 0.05599) employee = self._createEmployee() employee.company_id.nc_unemp_rate_2018 = 0.06 @@ -119,16 +119,16 @@ class TestUsNCPayslip(TestUsPayslip): allowance_multiplier = 96.15 PST = 336.54 - exceptions = 2 + allowances = 2 # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf - wh = round((salary - (PST + (allowance_multiplier * exceptions))) * 0.05599) + wh = -round((salary - (PST + (allowance_multiplier * allowances))) * 0.05599) employee = self._createEmployee() employee.company_id.nc_unemp_rate_2018 = 0.06 contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) - contract.nc_nc4_allowances = exceptions + contract.nc_nc4_allowances = allowances self.assertEqual(contract.schedule_pay, 'bi-weekly') @@ -172,17 +172,17 @@ class TestUsNCPayslip(TestUsPayslip): allowance_multiplier = 104.17 PST = 583.33 - exceptions = 1 + allowances = 1 # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf - wh = round((salary - (PST + (allowance_multiplier * exceptions))) * 0.05599) + wh = -round((salary - (PST + (allowance_multiplier * allowances))) * 0.05599) employee = self._createEmployee() employee.company_id.nc_unemp_rate_2018 = 0.06 contract = self._createContract(employee, salary, struct_id=self.ref( 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) - contract.nc_nc4_allowances = exceptions + contract.nc_nc4_allowances = allowances contract.nc_nc4_filing_status = nc_nc4_filing_status self.assertEqual(contract.schedule_pay, 'semi-monthly') @@ -219,24 +219,23 @@ class TestUsNCPayslip(TestUsPayslip): self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) def test_2018_taxes_monthly(self): - self.debug = True salary = 4000.0 schedule_pay = 'monthly' # allowance_multiplier and Portion of Standard Deduction for weekly allowance_multiplier = 208.33 PST = 729.17 - exceptions = 1 + allowances = 1 # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf - wh = round((salary - (PST + (allowance_multiplier * exceptions))) * 0.05599) + wh = -round((salary - (PST + (allowance_multiplier * allowances))) * 0.05599) employee = self._createEmployee() employee.company_id.nc_unemp_rate_2018 = 0.06 contract = self._createContract(employee, salary, struct_id=self.ref( 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) - contract.nc_nc4_allowances = exceptions + contract.nc_nc4_allowances = allowances self.assertEqual(contract.schedule_pay, 'monthly') @@ -320,3 +319,63 @@ class TestUsNCPayslip(TestUsPayslip): self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) + + def test_additional_withholding(self): + salary = 4000.0 + schedule_pay = 'weekly' + # allowance_multiplier and Portion of Standard Deduction for weekly + allowance_multiplier = 48.08 + PST = 168.27 + additional_wh = 40.0 + + #4000 - (168.27 + (48.08 * 1) + + allowances = 1 + # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf + + wh = -round(((salary - (PST + (allowance_multiplier * allowances))) * 0.05599) + additional_wh) + + employee = self._createEmployee() + employee.company_id.nc_unemp_rate_2018 = 0.06 + + contract = self._createContract(employee, + salary, + struct_id=self.ref('l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), + schedule_pay=schedule_pay) + contract.w4_is_nonresident_alien = True + contract.nc_nc4_additional_wh = additional_wh + contract.nc_nc4_allowances = allowances + + self.assertEqual(contract.schedule_pay, 'weekly') + self.assertEqual(contract.w4_is_nonresident_alien, True) + + # tax rates + nc_unemp = contract.nc_unemp_rate(2018) / -100.0 + + self._log('2018 North Carolina tax first payslip weekly:') + payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) + self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) + self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_nc_unemp_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ + else salary + + self._log('2018 North Carolina tax second payslip weekly:') + payslip = self._createPayslip(employee, '2018-02-01', '2018-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) + self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) From 7ce5dcbd29acb5b009a88d22906a1e9e0bd2a5b1 Mon Sep 17 00:00:00 2001 From: Kristen Marie Kulha Date: Fri, 15 Jun 2018 11:32:42 -0700 Subject: [PATCH 03/10] Add README to `l10n_us_nc_hr_payroll` --- l10n_us_nc_hr_payroll/README.rst | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 l10n_us_nc_hr_payroll/README.rst diff --git a/l10n_us_nc_hr_payroll/README.rst b/l10n_us_nc_hr_payroll/README.rst new file mode 100644 index 00000000..fad4ccf4 --- /dev/null +++ b/l10n_us_nc_hr_payroll/README.rst @@ -0,0 +1,41 @@ +***************************************** +Hibou - US Payroll - North Carolina State +***************************************** + +Calculations and contribution registers for North Carolina State Payroll. + +For more information and add-ons, visit `Hibou.io `_. + +============= +Main Features +============= + +* Contribution registers and partners for: + * North Carolina Department of Revenue - Income Tax withholding + * North Carolina Department of Taxation - Unemployment +* Contract level North Carolina Exemptions +* Company level North Carolina Unemployment Rate + +.. image:: https://user-images.githubusercontent.com/15882954/41436210-cb7f6a52-6fd5-11e8-9095-48799360f4e9.png + :alt: 'Employee Contract Detail' + :width: 988 + :align: left + +USA North Carolina Employee added to Contract Salary Structure menu + +.. image:: https://user-images.githubusercontent.com/15882954/41436282-fcfd3096-6fd5-11e8-8bc8-3c4985908b23.png + :alt: 'Computed Pay Slip Detail' + :width: 988 + :align: left + +New Payslip Categories for: + +* North Carolina Income Withholding +* North Carolina Unemployment - Wages +* North Carolina Unemployment. + +======= +License +======= +Please see `LICENSE `_. +Copyright Hibou Corp. 2018 From 859667659025a95a0194d210a883dafdac5db90e Mon Sep 17 00:00:00 2001 From: Kristen Marie Kulha Date: Thu, 12 Jul 2018 16:34:06 -0700 Subject: [PATCH 04/10] Change `rules_2018.xml` in `l10n_us_nc_hr_payroll` to ensure no positive withholding by checking withholding calculation is greater than zero before making it the result. Added test for low salary that would result in underflow. --- l10n_us_nc_hr_payroll/data/rules_2018.xml | 6 ++- .../tests/test_us_nc_payslip_2018.py | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/l10n_us_nc_hr_payroll/data/rules_2018.xml b/l10n_us_nc_hr_payroll/data/rules_2018.xml index 58e1f83a..d73ba291 100755 --- a/l10n_us_nc_hr_payroll/data/rules_2018.xml +++ b/l10n_us_nc_hr_payroll/data/rules_2018.xml @@ -95,7 +95,11 @@ else: if contract.nc_nc4_filing_status == 'exempt': result = 0 else: - result = -round(((wages - (PST + (allowance_multiplier * allowances))) * 0.05599) + contract.nc_nc4_additional_wh) + withholding = round(((wages - (PST + (allowance_multiplier * allowances))) * 0.05599) + contract.nc_nc4_additional_wh) + if withholding > 0.0: + result = - withholding + else: + result = 0 diff --git a/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py b/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py index 249acc27..d7d34a0d 100755 --- a/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py +++ b/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py @@ -379,3 +379,40 @@ class TestUsNCPayslip(TestUsPayslip): self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) + + def test_underflow(self): + salary = 150.0 + schedule_pay = 'weekly' + # allowance_multiplier and Portion of Standard Deduction for weekly + allowance_multiplier = 48.08 + PST = 168.27 + + exemption = 1 + + # Withholding should be 0, since pay is so low it's less than PST. + wh = 0.0 + + employee = self._createEmployee() + employee.company_id.nc_unemp_rate_2018 = 0.06 + + contract = self._createContract(employee, salary, struct_id=self.ref( + 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + contract.nc_nc4_allowances = exemption + + self.assertEqual(contract.schedule_pay, 'weekly') + + # tax rates + nc_unemp = contract.nc_unemp_rate(2018) / -100.0 + + self._log('2018 North Carolina tax first payslip weekly:') + payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) + self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) + self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) From 1df2dd71d5d8d277897cb53ff3cd7b560b1ac23c Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Sun, 9 Dec 2018 11:51:01 -0800 Subject: [PATCH 05/10] Refactor to mitigate the fact that eligible 401(k) contributions reduce taxable wage (gross) but not FICA/FUTA etc. This refactor bases all/most 'wage' categories off of BASIC instead of GROSS to allow all 'Income Tax' rules to continue to be based on GROSS. --- l10n_us_nc_hr_payroll/data/rules_2018.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/l10n_us_nc_hr_payroll/data/rules_2018.xml b/l10n_us_nc_hr_payroll/data/rules_2018.xml index d73ba291..967c21cc 100755 --- a/l10n_us_nc_hr_payroll/data/rules_2018.xml +++ b/l10n_us_nc_hr_payroll/data/rules_2018.xml @@ -17,10 +17,10 @@ ytd += contract.external_wages remaining = 7000.0 - ytd if remaining <= 0.0: result = 0 -elif remaining < categories.GROSS: +elif remaining < categories.BASIC: result = remaining else: - result = categories.GROSS + result = categories.BASIC From 58ca6c64d8070ed3b22e1a70854b64da91c12731 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Sun, 6 Jan 2019 17:06:37 -0800 Subject: [PATCH 06/10] Update `l10n_us_hr_payroll` for 2019 Federal Rates and Limits. --- l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py b/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py index d7d34a0d..12612f50 100755 --- a/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py +++ b/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py @@ -1,5 +1,5 @@ from odoo.addons.l10n_us_hr_payroll.tests.test_us_payslip import TestUsPayslip, process_payslip -from odoo.addons.l10n_us_hr_payroll.l10n_us_hr_payroll import USHrContract +from odoo.addons.l10n_us_hr_payroll.models.l10n_us_hr_payroll import USHrContract class TestUsNCPayslip(TestUsPayslip): From bf7d84bdd6e3dc042e268c3d71f96d83e9945336 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Mon, 7 Jan 2019 08:43:51 -0800 Subject: [PATCH 07/10] Migrate `l10n_us_nc_hr_payroll` for 2019 and to use `hr.payroll.rate` instead of company field. --- l10n_us_nc_hr_payroll/__init__.py | 2 +- l10n_us_nc_hr_payroll/__manifest__.py | 5 +- l10n_us_nc_hr_payroll/data/base.xml | 12 +- l10n_us_nc_hr_payroll/data/rates.xml | 19 + l10n_us_nc_hr_payroll/data/rules.xml | 153 +++++++ l10n_us_nc_hr_payroll/data/rules_2018.xml | 109 ----- l10n_us_nc_hr_payroll/models/__init__.py | 1 + .../{ => models}/hr_payroll.py | 18 - l10n_us_nc_hr_payroll/tests/__init__.py | 1 + .../tests/test_us_nc_payslip_2018.py | 134 +++---- .../tests/test_us_nc_payslip_2019.py | 379 ++++++++++++++++++ .../hr_payroll_views.xml} | 13 - 12 files changed, 610 insertions(+), 236 deletions(-) create mode 100755 l10n_us_nc_hr_payroll/data/rates.xml create mode 100755 l10n_us_nc_hr_payroll/data/rules.xml delete mode 100755 l10n_us_nc_hr_payroll/data/rules_2018.xml create mode 100644 l10n_us_nc_hr_payroll/models/__init__.py rename l10n_us_nc_hr_payroll/{ => models}/hr_payroll.py (54%) create mode 100755 l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2019.py rename l10n_us_nc_hr_payroll/{hr_payroll_view.xml => views/hr_payroll_views.xml} (63%) diff --git a/l10n_us_nc_hr_payroll/__init__.py b/l10n_us_nc_hr_payroll/__init__.py index e99aa24a..0650744f 100755 --- a/l10n_us_nc_hr_payroll/__init__.py +++ b/l10n_us_nc_hr_payroll/__init__.py @@ -1 +1 @@ -from . import hr_payroll +from . import models diff --git a/l10n_us_nc_hr_payroll/__manifest__.py b/l10n_us_nc_hr_payroll/__manifest__.py index 17df0ab6..801ecb2f 100755 --- a/l10n_us_nc_hr_payroll/__manifest__.py +++ b/l10n_us_nc_hr_payroll/__manifest__.py @@ -18,9 +18,10 @@ USA::North Carolina Payroll Rules. 'auto_install': False, 'website': 'https://hibou.io/', 'data': [ - 'hr_payroll_view.xml', + 'views/hr_payroll_views.xml', 'data/base.xml', - 'data/rules_2018.xml', + 'data/rates.xml', + 'data/rules.xml', 'data/final.xml', ], 'installable': True diff --git a/l10n_us_nc_hr_payroll/data/base.xml b/l10n_us_nc_hr_payroll/data/base.xml index 5640ec00..fdefcda9 100755 --- a/l10n_us_nc_hr_payroll/data/base.xml +++ b/l10n_us_nc_hr_payroll/data/base.xml @@ -26,19 +26,19 @@ - North Carolina Unemployment - Wages - NC_UNEMP_WAGES + Wage: US-NC Unemployment + WAGE_US_NC_UNEMP - North Carolina Unemployment - NC_UNEMP + ER: US-NC Unemployment + ER_US_NC_UNEMP - North Carolina Income Withholding - NC_INC_WITHHOLD + EE: US-NC Income Tax Withholding + EE_US_NC_INC_WITHHOLD diff --git a/l10n_us_nc_hr_payroll/data/rates.xml b/l10n_us_nc_hr_payroll/data/rates.xml new file mode 100755 index 00000000..1aaebf0d --- /dev/null +++ b/l10n_us_nc_hr_payroll/data/rates.xml @@ -0,0 +1,19 @@ + + + + + US NC Unemployment + US_NC_UNEMP + 0.6 + 2018-01-01 + + + + US NC Unemployment + US_NC_UNEMP + 1.0 + 2019-01-01 + + + + diff --git a/l10n_us_nc_hr_payroll/data/rules.xml b/l10n_us_nc_hr_payroll/data/rules.xml new file mode 100755 index 00000000..5771a59b --- /dev/null +++ b/l10n_us_nc_hr_payroll/data/rules.xml @@ -0,0 +1,153 @@ + + + + + + + + + Wage: US-NC Unemployment + WAGE_US_NC_UNEMP + python + result = (contract.futa_type != contract.FUTA_TYPE_BASIC) + code + +rate = payslip.dict.get_rate('US_NC_UNEMP') +year = int(payslip.dict.date_from[:4]) +ytd = payslip.sum('NC_UNEMP_WAGES_2018', str(year) + '-01-01', str(year+1) + '-01-01') +ytd += contract.external_wages +remaining = rate.wage_limit_year - ytd +if remaining <= 0.0: + result = 0 +elif remaining < categories.BASIC: + result = remaining +else: + result = categories.BASIC + + + + + + + + ER: US-NC Unemployment + ER_US_NC_UNEMP + python + result = (contract.futa_type != contract.FUTA_TYPE_BASIC) + code + +rate = payslip.dict.get_rate('US_NC_UNEMP') +result_rate = -rate.rate +result = categories.WAGE_US_NC_UNEMP + +# result_rate of 0 implies 100% due to bug +if result_rate == 0.0: + result = 0.0 + + + + + + + + + EE: US-NC Income Tax Withholding + EE_US_NC_INC_WITHHOLD + python + result = True + code + +wages = categories.GROSS +allowances = contract.nc_nc4_allowances +schedule_pay = contract.schedule_pay +val = 0.00 + + +# PST -> Portion of standard deduction +if year == 2018: + PST = 0.0 + allowance_multiplier = 0.0 + if 'weekly' == schedule_pay: + allowance_multiplier = 48.08 + if contract.nc_nc4_filing_status == 'head_household': + PST = 269.23 + else: + PST = 168.27 + elif 'bi-weekly' == schedule_pay: + allowance_multiplier = 96.15 + if contract.nc_nc4_filing_status == 'head_household': + PST = 538.46 + else: + PST = 336.54 + elif 'semi-monthly' == schedule_pay: + allowance_multiplier = 104.17 + if contract.nc_nc4_filing_status == 'head_household': + PST = 583.33 + else: + PST = 364.58 + elif 'monthly' == schedule_pay: + allowance_multiplier = 208.33 + if contract.nc_nc4_filing_status == 'head_household': + PST = 1166.67 + else: + PST = 729.17 + + else: + raise Exception('Invalid schedule_pay="' + schedule_pay + '" for NC Income Withholding calculation') + + # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf + if contract.nc_nc4_filing_status == 'exempt': + result = 0 + else: + withholding = round(((wages - (PST + (allowance_multiplier * allowances))) * 0.05599) + contract.nc_nc4_additional_wh) + if withholding > 0.0: + result = - withholding + else: + result = 0 +else: + PST = 0.0 + allowance_multiplier = 0.0 + if 'weekly' == schedule_pay: + allowance_multiplier = 48.08 + if contract.nc_nc4_filing_status == 'head_household': + PST = 288.46 + else: + PST = 192.31 + elif 'bi-weekly' == schedule_pay: + allowance_multiplier = 96.15 + if contract.nc_nc4_filing_status == 'head_household': + PST = 576.92 + else: + PST = 384.62 + elif 'semi-monthly' == schedule_pay: + allowance_multiplier = 104.17 + if contract.nc_nc4_filing_status == 'head_household': + PST = 625.00 + else: + PST = 416.67 + elif 'monthly' == schedule_pay: + allowance_multiplier = 208.33 + if contract.nc_nc4_filing_status == 'head_household': + PST = 1250.00 + else: + PST = 833.33 + + else: + raise Exception('Invalid schedule_pay="' + schedule_pay + '" for NC Income Withholding calculation') + + # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf + if contract.nc_nc4_filing_status == 'exempt': + result = 0 + else: + withholding = round(((wages - (PST + (allowance_multiplier * allowances))) * 0.0535) + contract.nc_nc4_additional_wh) + if withholding > 0.0: + result = - withholding + else: + result = 0 + + + + + + + diff --git a/l10n_us_nc_hr_payroll/data/rules_2018.xml b/l10n_us_nc_hr_payroll/data/rules_2018.xml deleted file mode 100755 index 967c21cc..00000000 --- a/l10n_us_nc_hr_payroll/data/rules_2018.xml +++ /dev/null @@ -1,109 +0,0 @@ - - - - - - - - - North Carolina Unemployment - Wages (2018) - NC_UNEMP_WAGES_2018 - python - result = (payslip.date_to[:4] == '2018') - code - -ytd = payslip.sum('NC_UNEMP_WAGES_2018', '2018-01-01', '2019-01-01') -ytd += contract.external_wages -remaining = 7000.0 - ytd -if remaining <= 0.0: - result = 0 -elif remaining < categories.BASIC: - result = remaining -else: - result = categories.BASIC - - - - - - - - North Carolina Unemployment (2018) - NC_UNEMP_2018 - python - result = (payslip.date_to[:4] == '2018') - code - -result_rate = -contract.nc_unemp_rate(2018) -result = categories.NC_UNEMP_WAGES - -# result_rate of 0 implies 100% due to bug -if result_rate == 0.0: - result = 0.0 - - - - - - - - - North Carolina Income Withholding - NC_INC_WITHHOLD_2018 - python - result = (payslip.date_to[:4] == '2018') - code - -wages = categories.GROSS -allowances = contract.nc_nc4_allowances -schedule_pay = contract.schedule_pay -val = 0.00 - - -# PST -> Portion of standard deduction -PST = 0.0 -allowance_multiplier = 0.0 -if 'weekly' == schedule_pay: - allowance_multiplier = 48.08 - if contract.nc_nc4_filing_status == 'head_household': - PST = 269.23 - else: - PST = 168.27 -elif 'bi-weekly' == schedule_pay: - allowance_multiplier = 96.15 - if contract.nc_nc4_filing_status == 'head_household': - PST = 538.46 - else: - PST = 336.54 -elif 'semi-monthly' == schedule_pay: - allowance_multiplier = 104.17 - if contract.nc_nc4_filing_status == 'head_household': - PST = 583.33 - else: - PST = 364.58 -elif 'monthly' == schedule_pay: - allowance_multiplier = 208.33 - if contract.nc_nc4_filing_status == 'head_household': - PST = 1166.67 - else: - PST = 729.17 - -else: - raise Exception('Invalid schedule_pay="' + schedule_pay + '" for NC Income Withholding calculation') - -# Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf -if contract.nc_nc4_filing_status == 'exempt': - result = 0 -else: - withholding = round(((wages - (PST + (allowance_multiplier * allowances))) * 0.05599) + contract.nc_nc4_additional_wh) - if withholding > 0.0: - result = - withholding - else: - result = 0 - - - - - - - diff --git a/l10n_us_nc_hr_payroll/models/__init__.py b/l10n_us_nc_hr_payroll/models/__init__.py new file mode 100644 index 00000000..e99aa24a --- /dev/null +++ b/l10n_us_nc_hr_payroll/models/__init__.py @@ -0,0 +1 @@ +from . import hr_payroll diff --git a/l10n_us_nc_hr_payroll/hr_payroll.py b/l10n_us_nc_hr_payroll/models/hr_payroll.py similarity index 54% rename from l10n_us_nc_hr_payroll/hr_payroll.py rename to l10n_us_nc_hr_payroll/models/hr_payroll.py index a4eb8572..0746427c 100755 --- a/l10n_us_nc_hr_payroll/hr_payroll.py +++ b/l10n_us_nc_hr_payroll/models/hr_payroll.py @@ -15,21 +15,3 @@ class USNCHrContract(models.Model): nc_nc4_additional_wh = fields.Float(string="Additional Witholding", default=0.0, help="If you are filling out NC-4 NRA, this would be box 4; " \ "otherwise box 2.") - - @api.multi - def nc_unemp_rate(self, year): - self.ensure_one() - if self.futa_type == self.FUTA_TYPE_BASIC: - return 0.0 - - if hasattr(self.employee_id.company_id, 'nc_unemp_rate_' + str(year)): - return self.employee_id.company_id['nc_unemp_rate_' + str(year)] - - raise NotImplemented('Year (' + str(year) + ') Not implemented for US North Carolina.') - - -class NCCompany(models.Model): - _inherit = 'res.company' - - # Unemployment rate provided by Katherine - nc_unemp_rate_2018 = fields.Float(string="North Carolina Unemployment Rate 2018", default=0.06) diff --git a/l10n_us_nc_hr_payroll/tests/__init__.py b/l10n_us_nc_hr_payroll/tests/__init__.py index 5e31343d..f5eee306 100755 --- a/l10n_us_nc_hr_payroll/tests/__init__.py +++ b/l10n_us_nc_hr_payroll/tests/__init__.py @@ -1 +1,2 @@ from . import test_us_nc_payslip_2018 +from . import test_us_nc_payslip_2019 diff --git a/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py b/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py index 12612f50..eb5079fe 100755 --- a/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py +++ b/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2018.py @@ -6,7 +6,8 @@ class TestUsNCPayslip(TestUsPayslip): ### # Taxes and Rates ### - NC_UNEMP_MAX_WAGE = 7000.0 + NC_UNEMP_MAX_WAGE = 23500.0 + NC_UNEMP = -0.6 / 100.0 def test_2018_taxes_weekly(self): @@ -22,17 +23,12 @@ class TestUsNCPayslip(TestUsPayslip): wh = -round((salary - (PST + (allowance_multiplier * exemption))) * 0.05599) employee = self._createEmployee() - employee.company_id.nc_unemp_rate_2018 = 0.06 contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) contract.nc_nc4_allowances = exemption self.assertEqual(contract.schedule_pay, 'weekly') - # tax rates - nc_unemp = contract.nc_unemp_rate(2018) / -100.0 - - self._log('2018 North Carolina tax first payslip weekly:') payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') @@ -40,15 +36,15 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) - self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) - self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) process_payslip(payslip) # Make a new payslip, this one will have maximums - remaining_nc_unemp_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2*salary < salary) \ + remaining_NC_UNEMP_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2*salary < salary) \ else salary self._log('2018 North Carolina tax second payslip weekly:') @@ -58,24 +54,20 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) - self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], remaining_NC_UNEMP_wages) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], remaining_NC_UNEMP_wages * self.NC_UNEMP) def test_2018_taxes_with_external_weekly(self): salary = 5000.0 - external_wages = 7000.0 + external_wages = 30000.0 schedule_pay = 'weekly' employee = self._createEmployee() - employee.company_id.nc_unemp_rate_2018 = 0.06 contract = self._createContract(employee, salary, external_wages=external_wages, struct_id=self.ref('l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) - # tax rates - nc_unemp = contract.nc_unemp_rate(2018) / -100.0 - self._log('2018 NorthCarolina_external tax first payslip weekly:') payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') @@ -83,25 +75,19 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], self.NC_UNEMP_MAX_WAGE - external_wages) - self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], max(self.NC_UNEMP_MAX_WAGE - external_wages, 0.0)) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) def test_2018_taxes_with_state_exempt_weekly(self): salary = 5000.0 - external_wages = 6000.0 + external_wages = 10000.0 schedule_pay = 'weekly' employee = self._createEmployee() - employee.company_id.nc_unemp_rate_2018 = 0.06 contract = self._createContract(employee, salary, external_wages=external_wages, struct_id=self.ref( 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), futa_type=USHrContract.FUTA_TYPE_BASIC, schedule_pay=schedule_pay) - # tax rates - nc_unemp = contract.nc_unemp_rate(2018) / -100.0 - - self.assertPayrollEqual(nc_unemp, 0.0) - self._log('2018 North Carolina exempt tax first payslip weekly:') payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') @@ -109,8 +95,8 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], self.NC_UNEMP_MAX_WAGE - external_wages) - self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) + self.assertPayrollEqual(cats.get('WAGE_US_NC_UNEMP', 0.0), 0.0) + self.assertPayrollEqual(cats.get('ER_US_NC_UNEMP', 0.0), cats.get('WAGE_US_NC_UNEMP', 0.0) * self.NC_UNEMP) def test_2018_taxes_biweekly(self): salary = 5000.0 @@ -125,17 +111,12 @@ class TestUsNCPayslip(TestUsPayslip): wh = -round((salary - (PST + (allowance_multiplier * allowances))) * 0.05599) employee = self._createEmployee() - employee.company_id.nc_unemp_rate_2018 = 0.06 contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) contract.nc_nc4_allowances = allowances self.assertEqual(contract.schedule_pay, 'bi-weekly') - # tax rates - nc_unemp = contract.nc_unemp_rate(2018) / -100.0 - - self._log('2018 North Carolina tax first payslip bi-weekly:') payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') @@ -143,15 +124,15 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) - self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) - self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) process_payslip(payslip) # Make a new payslip, this one will have maximums - remaining_nc_unemp_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2*salary < salary) \ + remaining_NC_UNEMP_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2*salary < salary) \ else salary self._log('2018 North Carolina tax second payslip bi-weekly:') @@ -161,8 +142,8 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) - self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], remaining_NC_UNEMP_wages) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], remaining_NC_UNEMP_wages * self.NC_UNEMP) def test_2018_taxes_semimonthly(self): salary = 4000.0 @@ -178,7 +159,6 @@ class TestUsNCPayslip(TestUsPayslip): wh = -round((salary - (PST + (allowance_multiplier * allowances))) * 0.05599) employee = self._createEmployee() - employee.company_id.nc_unemp_rate_2018 = 0.06 contract = self._createContract(employee, salary, struct_id=self.ref( 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) @@ -187,9 +167,6 @@ class TestUsNCPayslip(TestUsPayslip): self.assertEqual(contract.schedule_pay, 'semi-monthly') - # tax rates - nc_unemp = contract.nc_unemp_rate(2018) / -100.0 - self._log('2018 North Carolina tax first payslip:') payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') @@ -197,15 +174,15 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) - self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) - self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) process_payslip(payslip) # Make a new payslip, this one will have maximums - remaining_nc_unemp_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ + remaining_NC_UNEMP_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ else salary self._log('2018 North Carolina tax second payslip:') @@ -215,8 +192,8 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) - self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], remaining_NC_UNEMP_wages) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], remaining_NC_UNEMP_wages * self.NC_UNEMP) def test_2018_taxes_monthly(self): salary = 4000.0 @@ -231,7 +208,6 @@ class TestUsNCPayslip(TestUsPayslip): wh = -round((salary - (PST + (allowance_multiplier * allowances))) * 0.05599) employee = self._createEmployee() - employee.company_id.nc_unemp_rate_2018 = 0.06 contract = self._createContract(employee, salary, struct_id=self.ref( 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) @@ -239,9 +215,6 @@ class TestUsNCPayslip(TestUsPayslip): self.assertEqual(contract.schedule_pay, 'monthly') - # tax rates - nc_unemp = contract.nc_unemp_rate(2018) / -100.0 - self._log('2018 North Carolina tax first payslip:') payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') @@ -249,15 +222,15 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) - self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) - self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) process_payslip(payslip) # Make a new payslip, this one will have maximums - remaining_nc_unemp_wages = self.NC_UNEMP_MAX_WAGE - salary if ( + remaining_NC_UNEMP_wages = self.NC_UNEMP_MAX_WAGE - salary if ( self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ else salary @@ -268,8 +241,8 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) - self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], remaining_NC_UNEMP_wages) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], remaining_NC_UNEMP_wages * self.NC_UNEMP) def test_tax_exempt(self): salary = 4000.0 @@ -278,7 +251,6 @@ class TestUsNCPayslip(TestUsPayslip): excemptions = 1 employee = self._createEmployee() - employee.company_id.nc_unemp_rate_2018 = 0.06 contract = self._createContract(employee, salary, struct_id=self.ref( 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) @@ -287,10 +259,6 @@ class TestUsNCPayslip(TestUsPayslip): self.assertEqual(contract.schedule_pay, 'weekly') - # tax rates - nc_unemp = contract.nc_unemp_rate(2018) / -100.0 - - self._log('2018 North Carolina tax first payslip:') payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') @@ -298,15 +266,15 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) - self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) - self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) process_payslip(payslip) # Make a new payslip, this one will have maximums - remaining_nc_unemp_wages = self.NC_UNEMP_MAX_WAGE - salary if ( + remaining_NC_UNEMP_wages = self.NC_UNEMP_MAX_WAGE - salary if ( self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ else salary @@ -317,8 +285,8 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) - self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], remaining_NC_UNEMP_wages) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], remaining_NC_UNEMP_wages * self.NC_UNEMP) def test_additional_withholding(self): salary = 4000.0 @@ -336,7 +304,6 @@ class TestUsNCPayslip(TestUsPayslip): wh = -round(((salary - (PST + (allowance_multiplier * allowances))) * 0.05599) + additional_wh) employee = self._createEmployee() - employee.company_id.nc_unemp_rate_2018 = 0.06 contract = self._createContract(employee, salary, @@ -349,9 +316,6 @@ class TestUsNCPayslip(TestUsPayslip): self.assertEqual(contract.schedule_pay, 'weekly') self.assertEqual(contract.w4_is_nonresident_alien, True) - # tax rates - nc_unemp = contract.nc_unemp_rate(2018) / -100.0 - self._log('2018 North Carolina tax first payslip weekly:') payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') @@ -359,15 +323,15 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) - self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) - self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) process_payslip(payslip) # Make a new payslip, this one will have maximums - remaining_nc_unemp_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ + remaining_NC_UNEMP_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ else salary self._log('2018 North Carolina tax second payslip weekly:') @@ -377,8 +341,8 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], remaining_nc_unemp_wages) - self.assertPayrollEqual(cats['NC_UNEMP'], remaining_nc_unemp_wages * nc_unemp) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], remaining_NC_UNEMP_wages) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], remaining_NC_UNEMP_wages * self.NC_UNEMP) def test_underflow(self): salary = 150.0 @@ -393,7 +357,6 @@ class TestUsNCPayslip(TestUsPayslip): wh = 0.0 employee = self._createEmployee() - employee.company_id.nc_unemp_rate_2018 = 0.06 contract = self._createContract(employee, salary, struct_id=self.ref( 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) @@ -401,9 +364,6 @@ class TestUsNCPayslip(TestUsPayslip): self.assertEqual(contract.schedule_pay, 'weekly') - # tax rates - nc_unemp = contract.nc_unemp_rate(2018) / -100.0 - self._log('2018 North Carolina tax first payslip weekly:') payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') @@ -411,8 +371,8 @@ class TestUsNCPayslip(TestUsPayslip): cats = self._getCategories(payslip) - self.assertPayrollEqual(cats['NC_UNEMP_WAGES'], salary) - self.assertPayrollEqual(cats['NC_UNEMP'], cats['NC_UNEMP_WAGES'] * nc_unemp) - self.assertPayrollEqual(cats['NC_INC_WITHHOLD'], wh) + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) process_payslip(payslip) diff --git a/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2019.py b/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2019.py new file mode 100755 index 00000000..2b30e8c1 --- /dev/null +++ b/l10n_us_nc_hr_payroll/tests/test_us_nc_payslip_2019.py @@ -0,0 +1,379 @@ +from odoo.addons.l10n_us_hr_payroll.tests.test_us_payslip import TestUsPayslip, process_payslip +from odoo.addons.l10n_us_hr_payroll.models.l10n_us_hr_payroll import USHrContract + + +class TestUsNCPayslip(TestUsPayslip): + ### + # Taxes and Rates + ### + NC_UNEMP_MAX_WAGE = 24300.0 + NC_UNEMP = -1.0 / 100.0 + NC_INC_TAX = -0.0535 + + + def test_2019_taxes_weekly(self): + salary = 5000.0 + schedule_pay = 'weekly' + # allowance_multiplier and Portion of Standard Deduction for weekly + allowance_multiplier = 48.08 + PST = 192.31 + + exemption = 1 + # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf + + wh = -round((salary - (PST + (allowance_multiplier * exemption))) * -self.NC_INC_TAX) + + employee = self._createEmployee() + + contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + contract.nc_nc4_allowances = exemption + + self.assertEqual(contract.schedule_pay, 'weekly') + + self._log('2019 North Carolina tax first payslip weekly:') + payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_NC_UNEMP_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2*salary < salary) \ + else salary + + self._log('2019 North Carolina tax second payslip weekly:') + payslip = self._createPayslip(employee, '2019-02-01', '2019-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], remaining_NC_UNEMP_wages) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], remaining_NC_UNEMP_wages * self.NC_UNEMP) + + def test_2019_taxes_with_external_weekly(self): + salary = 5000.0 + external_wages = 30000.0 + + schedule_pay = 'weekly' + + employee = self._createEmployee() + + contract = self._createContract(employee, salary, external_wages=external_wages, + struct_id=self.ref('l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + + self._log('2019 NorthCarolina_external tax first payslip weekly:') + payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], max(self.NC_UNEMP_MAX_WAGE - external_wages, 0.0)) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + + def test_2019_taxes_with_state_exempt_weekly(self): + salary = 5000.0 + external_wages = 10000.0 + schedule_pay = 'weekly' + + employee = self._createEmployee() + + contract = self._createContract(employee, salary, external_wages=external_wages, struct_id=self.ref( + 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), futa_type=USHrContract.FUTA_TYPE_BASIC, schedule_pay=schedule_pay) + + self._log('2019 North Carolina exempt tax first payslip weekly:') + payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats.get('WAGE_US_NC_UNEMP', 0.0), 0.0) + self.assertPayrollEqual(cats.get('ER_US_NC_UNEMP', 0.0), cats.get('WAGE_US_NC_UNEMP', 0.0) * self.NC_UNEMP) + + def test_2019_taxes_biweekly(self): + salary = 5000.0 + schedule_pay = 'bi-weekly' + # allowance_multiplier and Portion of Standard Deduction for weekly + allowance_multiplier = 96.15 + PST = 384.62 + + allowances = 2 + # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf + + wh = -round((salary - (PST + (allowance_multiplier * allowances))) * -self.NC_INC_TAX) + + employee = self._createEmployee() + + contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + contract.nc_nc4_allowances = allowances + + self.assertEqual(contract.schedule_pay, 'bi-weekly') + + self._log('2019 North Carolina tax first payslip bi-weekly:') + payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_NC_UNEMP_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2*salary < salary) \ + else salary + + self._log('2019 North Carolina tax second payslip bi-weekly:') + payslip = self._createPayslip(employee, '2019-02-01', '2019-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], remaining_NC_UNEMP_wages) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], remaining_NC_UNEMP_wages * self.NC_UNEMP) + + def test_2019_taxes_semimonthly(self): + salary = 4000.0 + schedule_pay = 'semi-monthly' + nc_nc4_filing_status = 'head_household' + # allowance_multiplier and Portion of Standard Deduction for weekly + allowance_multiplier = 104.17 + PST = 625.00 + + allowances = 1 + # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf + + wh = -round((salary - (PST + (allowance_multiplier * allowances))) * -self.NC_INC_TAX) + + employee = self._createEmployee() + + contract = self._createContract(employee, salary, struct_id=self.ref( + 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + contract.nc_nc4_allowances = allowances + contract.nc_nc4_filing_status = nc_nc4_filing_status + + self.assertEqual(contract.schedule_pay, 'semi-monthly') + + self._log('2019 North Carolina tax first payslip:') + payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_NC_UNEMP_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ + else salary + + self._log('2019 North Carolina tax second payslip:') + payslip = self._createPayslip(employee, '2019-02-01', '2019-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], remaining_NC_UNEMP_wages) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], remaining_NC_UNEMP_wages * self.NC_UNEMP) + + def test_2019_taxes_monthly(self): + salary = 4000.0 + schedule_pay = 'monthly' + # allowance_multiplier and Portion of Standard Deduction for weekly + allowance_multiplier = 208.33 + PST = 833.33 + + allowances = 1 + # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf + + wh = -round((salary - (PST + (allowance_multiplier * allowances))) * -self.NC_INC_TAX) + + employee = self._createEmployee() + + contract = self._createContract(employee, salary, struct_id=self.ref( + 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + contract.nc_nc4_allowances = allowances + + self.assertEqual(contract.schedule_pay, 'monthly') + + self._log('2019 North Carolina tax first payslip:') + payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_NC_UNEMP_wages = self.NC_UNEMP_MAX_WAGE - salary if ( + self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ + else salary + + self._log('2019 North Carolina tax second payslip:') + payslip = self._createPayslip(employee, '2019-02-01', '2019-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], remaining_NC_UNEMP_wages) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], remaining_NC_UNEMP_wages * self.NC_UNEMP) + + def test_tax_exempt(self): + salary = 4000.0 + wh = 0 + schedule_pay = 'weekly' + excemptions = 1 + + employee = self._createEmployee() + + contract = self._createContract(employee, salary, struct_id=self.ref( + 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + contract.nc_nc4_allowances = excemptions + contract.nc_nc4_filing_status = 'exempt' + + self.assertEqual(contract.schedule_pay, 'weekly') + + self._log('2019 North Carolina tax first payslip:') + payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_NC_UNEMP_wages = self.NC_UNEMP_MAX_WAGE - salary if ( + self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ + else salary + + self._log('2019 North Carolina tax second payslip:') + payslip = self._createPayslip(employee, '2019-02-01', '2019-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], remaining_NC_UNEMP_wages) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], remaining_NC_UNEMP_wages * self.NC_UNEMP) + + def test_additional_withholding(self): + salary = 4000.0 + schedule_pay = 'weekly' + # allowance_multiplier and Portion of Standard Deduction for weekly + allowance_multiplier = 48.08 + PST = 192.31 + additional_wh = 40.0 + + #4000 - (168.27 + (48.08 * 1) + + allowances = 1 + # Algorithm derived from percentage method in https://files.nc.gov/ncdor/documents/files/nc-30_book_web.pdf + + wh = -round(((salary - (PST + (allowance_multiplier * allowances))) * -self.NC_INC_TAX) + additional_wh) + + employee = self._createEmployee() + + contract = self._createContract(employee, + salary, + struct_id=self.ref('l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), + schedule_pay=schedule_pay) + contract.w4_is_nonresident_alien = True + contract.nc_nc4_additional_wh = additional_wh + contract.nc_nc4_allowances = allowances + + self.assertEqual(contract.schedule_pay, 'weekly') + self.assertEqual(contract.w4_is_nonresident_alien, True) + + self._log('2019 North Carolina tax first payslip weekly:') + payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_NC_UNEMP_wages = self.NC_UNEMP_MAX_WAGE - salary if (self.NC_UNEMP_MAX_WAGE - 2 * salary < salary) \ + else salary + + self._log('2019 North Carolina tax second payslip weekly:') + payslip = self._createPayslip(employee, '2019-02-01', '2019-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], remaining_NC_UNEMP_wages) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], remaining_NC_UNEMP_wages * self.NC_UNEMP) + + def test_underflow(self): + salary = 150.0 + schedule_pay = 'weekly' + # allowance_multiplier and Portion of Standard Deduction for weekly + allowance_multiplier = 48.08 + PST = 192.31 + + exemption = 1 + + # Withholding should be 0, since pay is so low it's less than PST. + wh = 0.0 + + employee = self._createEmployee() + + contract = self._createContract(employee, salary, struct_id=self.ref( + 'l10n_us_nc_hr_payroll.hr_payroll_salary_structure_us_nc_employee'), schedule_pay=schedule_pay) + contract.nc_nc4_allowances = exemption + + self.assertEqual(contract.schedule_pay, 'weekly') + + self._log('2019 North Carolina tax first payslip weekly:') + payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['WAGE_US_NC_UNEMP'], salary) + self.assertPayrollEqual(cats['ER_US_NC_UNEMP'], cats['WAGE_US_NC_UNEMP'] * self.NC_UNEMP) + self.assertPayrollEqual(cats['EE_US_NC_INC_WITHHOLD'], wh) + + process_payslip(payslip) diff --git a/l10n_us_nc_hr_payroll/hr_payroll_view.xml b/l10n_us_nc_hr_payroll/views/hr_payroll_views.xml similarity index 63% rename from l10n_us_nc_hr_payroll/hr_payroll_view.xml rename to l10n_us_nc_hr_payroll/views/hr_payroll_views.xml index f8a454a2..ef850399 100755 --- a/l10n_us_nc_hr_payroll/hr_payroll_view.xml +++ b/l10n_us_nc_hr_payroll/views/hr_payroll_views.xml @@ -1,19 +1,6 @@ - - res.company.form - res.company - 64 - - - - - - - - - hr.contract.form.inherit hr.contract From d18a72d485858c5b9396bdcafbe299748da12a4e Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Mon, 7 Jan 2019 14:41:05 -0800 Subject: [PATCH 08/10] FIX `l10n_us_nc_hr_payroll` version bumped to 2019 --- l10n_us_nc_hr_payroll/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n_us_nc_hr_payroll/__manifest__.py b/l10n_us_nc_hr_payroll/__manifest__.py index 801ecb2f..0539a963 100755 --- a/l10n_us_nc_hr_payroll/__manifest__.py +++ b/l10n_us_nc_hr_payroll/__manifest__.py @@ -4,7 +4,7 @@ 'license': 'AGPL-3', 'category': 'Localization', 'depends': ['l10n_us_hr_payroll'], - 'version': '11.0.2018.0.0', + 'version': '11.0.2019.0.0', 'description': """ USA::North Carolina Payroll Rules. ================================== From 8746433a61e874afdff1e182e5772a9365406aa6 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Wed, 16 Jan 2019 09:47:58 -0800 Subject: [PATCH 09/10] FIX Correct payslip wage base for payslips in two years. Add 2019 Ohio Tax Withholding rate. --- l10n_us_nc_hr_payroll/data/rules.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n_us_nc_hr_payroll/data/rules.xml b/l10n_us_nc_hr_payroll/data/rules.xml index 5771a59b..1885fe4c 100755 --- a/l10n_us_nc_hr_payroll/data/rules.xml +++ b/l10n_us_nc_hr_payroll/data/rules.xml @@ -13,7 +13,7 @@ code rate = payslip.dict.get_rate('US_NC_UNEMP') -year = int(payslip.dict.date_from[:4]) +year = int(payslip.dict.date_to[:4]) ytd = payslip.sum('NC_UNEMP_WAGES_2018', str(year) + '-01-01', str(year+1) + '-01-01') ytd += contract.external_wages remaining = rate.wage_limit_year - ytd From 64316290b665160d013c9438044fe4f787baa9e0 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Sun, 10 Feb 2019 15:51:56 -0800 Subject: [PATCH 10/10] MIG `l10n_us_nc_hr_payroll` to 12.0 and FIX apparent missing year in rules calculation. --- l10n_us_nc_hr_payroll/__manifest__.py | 2 +- l10n_us_nc_hr_payroll/data/rules.xml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/l10n_us_nc_hr_payroll/__manifest__.py b/l10n_us_nc_hr_payroll/__manifest__.py index 0539a963..4960939c 100755 --- a/l10n_us_nc_hr_payroll/__manifest__.py +++ b/l10n_us_nc_hr_payroll/__manifest__.py @@ -4,7 +4,7 @@ 'license': 'AGPL-3', 'category': 'Localization', 'depends': ['l10n_us_hr_payroll'], - 'version': '11.0.2019.0.0', + 'version': '12.0.2019.0.0', 'description': """ USA::North Carolina Payroll Rules. ================================== diff --git a/l10n_us_nc_hr_payroll/data/rules.xml b/l10n_us_nc_hr_payroll/data/rules.xml index 1885fe4c..8d06ea80 100755 --- a/l10n_us_nc_hr_payroll/data/rules.xml +++ b/l10n_us_nc_hr_payroll/data/rules.xml @@ -13,7 +13,7 @@ code rate = payslip.dict.get_rate('US_NC_UNEMP') -year = int(payslip.dict.date_to[:4]) +year = payslip.dict.date_to.year ytd = payslip.sum('NC_UNEMP_WAGES_2018', str(year) + '-01-01', str(year+1) + '-01-01') ytd += contract.external_wages remaining = rate.wage_limit_year - ytd @@ -57,6 +57,7 @@ if result_rate == 0.0: result = True code +year = payslip.dict.date_to.year wages = categories.GROSS allowances = contract.nc_nc4_allowances schedule_pay = contract.schedule_pay