From d7f17b334a952f2bd50395e58917c5f3f9dd4b9a Mon Sep 17 00:00:00 2001 From: Kristen Marie Kulha Date: Thu, 3 May 2018 15:37:19 -0700 Subject: [PATCH] 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)