diff --git a/l10n_us_oh_hr_payroll/__init__.py b/l10n_us_oh_hr_payroll/__init__.py new file mode 100755 index 00000000..c90f169b --- /dev/null +++ b/l10n_us_oh_hr_payroll/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import hr_payroll \ No newline at end of file diff --git a/l10n_us_oh_hr_payroll/__manifest__.py b/l10n_us_oh_hr_payroll/__manifest__.py new file mode 100755 index 00000000..61333e17 --- /dev/null +++ b/l10n_us_oh_hr_payroll/__manifest__.py @@ -0,0 +1,31 @@ +# -*- encoding: utf-8 -*- +{ + 'name': 'USA - Ohio - Payroll', + 'author': 'Hibou Corp. ', + 'license': 'AGPL-3', + 'category': 'Localization', + 'depends': ['l10n_us_hr_payroll'], + 'version': '11.0.2017.0.0', + 'description': """ +USA::Ohio Payroll Rules. +======================== + + * Ohio Department of Revenue partner + * Contribution register for Ohio DoR Unemployment + * Contribution register for Ohio DoR Income Tax Withholding + * Contract level Ohio Withholding Allowance + * Company level Ohio Unemployment Rate + """, + + 'auto_install': False, + 'website': 'https://hibou.io/', + 'data':[ + 'hr_payroll_view.xml', + 'data/base.xml', + 'data/rules_2016.xml', + 'data/rules_2017.xml', + 'data/rules_2018.xml', + 'data/final.xml', + ], + 'installable': True +} diff --git a/l10n_us_oh_hr_payroll/data/base.xml b/l10n_us_oh_hr_payroll/data/base.xml new file mode 100755 index 00000000..f09bda5a --- /dev/null +++ b/l10n_us_oh_hr_payroll/data/base.xml @@ -0,0 +1,46 @@ + + + + + + Ohio OBG - Unemployment + 1 + + + + Ohio OBG - Income Withholding + 1 + + + + Ohio Unemployment + Ohio Treasurer of State - Unemployment + + + + Ohio Income Tax Withholding + Ohio Treasurer of State - Income Tax Withholding + + + + + + + Ohio Unemployment - Wages + OH_UNEMP_WAGES + + + + Ohio Unemployment + OH_UNEMP + + + + + Ohio Income Withholding + OH_INC_WITHHOLD + + + + + diff --git a/l10n_us_oh_hr_payroll/data/final.xml b/l10n_us_oh_hr_payroll/data/final.xml new file mode 100755 index 00000000..d2e818f5 --- /dev/null +++ b/l10n_us_oh_hr_payroll/data/final.xml @@ -0,0 +1,27 @@ + + + + + + + US_OH_EMP + USA Ohio Employee + + + + + + + diff --git a/l10n_us_oh_hr_payroll/data/rules_2016.xml b/l10n_us_oh_hr_payroll/data/rules_2016.xml new file mode 100755 index 00000000..2943f200 --- /dev/null +++ b/l10n_us_oh_hr_payroll/data/rules_2016.xml @@ -0,0 +1,104 @@ + + + + + + + + + Ohio Unemployment - Wages (2016) + OH_UNEMP_WAGES_2016 + python + result = (payslip.date_to[:4] == '2016') + code + +### +ytd = payslip.sum('OH_UNEMP_WAGES_2016', '2016-01-01', '2017-01-01') +ytd += contract.external_wages +remaining = 9000.0 - ytd +if remaining <= 0.0: + result = 0 +elif remaining < categories.GROSS: + result = remaining +else: + result = categories.GROSS + + + + + + + Ohio Unemployment (2016) + OH_UNEMP_2016 + python + result = (payslip.date_to[:4] == '2016') + code + +result_rate = -contract.oh_unemp_rate(2016) +result = categories.OH_UNEMP_WAGES + +# result_rate of 0 implies 100% due to bug +if result_rate == 0.0: + result = 0.0 + + + + + + + + + Ohio Income Withholding + OH_INC_WITHHOLD_2016 + python + result = (payslip.date_to[:4] == '2016') + code + +wages = categories.GROSS +allowances = contract.oh_income_allowances +schedule_pay = contract.schedule_pay +val = 0.00 + +PP = 0 +if 'weekly' == schedule_pay: + PP = 52 +elif 'bi-weekly' == schedule_pay: + PP = 26 +elif 'semi-monthly' == schedule_pay: # impossible + PP = 24 +elif 'monthly' == schedule_pay: + PP = 12 +elif 'quarterly' == schedule_pay: + PP = 4 +elif 'semi-annually' == schedule_pay: + PP = 2 +elif 'annually' == schedule_pay: + PP = 1 +else: + raise Exception('Invalid schedule_pay="' + schedule_pay + '" for OH Income Withholding calculation') + +# Algorithm from http://www.tax.ohio.gov/Portals/0/employer_withholding/August2015Rates/WTH_OptionalComputerFormula_073015.pdf +TW = (wages * PP) - (650 * allowances) +if TW <= 5000.0: + WD = ((TW * 0.005) / PP) * 1.112 +elif TW <= 10000.0: + WD = ((((TW - 5000.0) * 0.01) + 25.0) / PP) * 1.112 +elif TW <= 15000.0: + WD = ((((TW - 10000.0) * 0.02) + 75.0) / PP) * 1.112 +elif TW <= 20000.0: + WD = ((((TW - 15000.0) * 0.025) + 175.0) / PP) * 1.112 +elif TW <= 40000.0: + WD = ((((TW - 20000.0) * 0.03) + 300.0) / PP) * 1.112 +elif TW <= 80000.0: + WD = ((((TW - 40000.0) * 0.035) + 900.0) / PP) * 1.112 +elif TW <= 100000.0: + WD = ((((TW - 80000.0) * 0.04) + 2300.0) / PP) * 1.112 +else: + WD = ((((TW - 100000.0) * 0.05) + 3100.0) / PP) * 1.112 +result = -WD + + + + + + diff --git a/l10n_us_oh_hr_payroll/data/rules_2017.xml b/l10n_us_oh_hr_payroll/data/rules_2017.xml new file mode 100755 index 00000000..c55a75f8 --- /dev/null +++ b/l10n_us_oh_hr_payroll/data/rules_2017.xml @@ -0,0 +1,104 @@ + + + + + + + + + Ohio Unemployment - Wages (2017) + OH_UNEMP_WAGES_2017 + python + result = (payslip.date_to[:4] == '2017') + code + +### +ytd = payslip.sum('OH_UNEMP_WAGES_2017', '2017-01-01', '2018-01-01') +ytd += contract.external_wages +remaining = 9000.0 - ytd +if remaining <= 0.0: + result = 0 +elif remaining < categories.GROSS: + result = remaining +else: + result = categories.GROSS + + + + + + + Ohio Unemployment (2017) + OH_UNEMP_2017 + python + result = (payslip.date_to[:4] == '2017') + code + +result_rate = -contract.oh_unemp_rate(2017) +result = categories.OH_UNEMP_WAGES + +# result_rate of 0 implies 100% due to bug +if result_rate == 0.0: + result = 0.0 + + + + + + + + + Ohio Income Withholding + OH_INC_WITHHOLD_2017 + python + result = (payslip.date_to[:4] == '2017') + code + +wages = categories.GROSS +allowances = contract.oh_income_allowances +schedule_pay = contract.schedule_pay +val = 0.00 + +PP = 0 +if 'weekly' == schedule_pay: + PP = 52 +elif 'bi-weekly' == schedule_pay: + PP = 26 +elif 'semi-monthly' == schedule_pay: # impossible + PP = 24 +elif 'monthly' == schedule_pay: + PP = 12 +elif 'quarterly' == schedule_pay: + PP = 4 +elif 'semi-annually' == schedule_pay: + PP = 2 +elif 'annually' == schedule_pay: + PP = 1 +else: + raise Exception('Invalid schedule_pay="' + schedule_pay + '" for OH Income Withholding calculation') + +# Algorithm from http://www.tax.ohio.gov/Portals/0/employer_withholding/August2015Rates/WTH_OptionalComputerFormula_073015.pdf +TW = (wages * PP) - (650 * allowances) +if TW <= 5000.0: + WD = ((TW * 0.005) / PP) * 1.112 +elif TW <= 10000.0: + WD = ((((TW - 5000.0) * 0.01) + 25.0) / PP) * 1.112 +elif TW <= 15000.0: + WD = ((((TW - 10000.0) * 0.02) + 75.0) / PP) * 1.112 +elif TW <= 20000.0: + WD = ((((TW - 15000.0) * 0.025) + 175.0) / PP) * 1.112 +elif TW <= 40000.0: + WD = ((((TW - 20000.0) * 0.03) + 300.0) / PP) * 1.112 +elif TW <= 80000.0: + WD = ((((TW - 40000.0) * 0.035) + 900.0) / PP) * 1.112 +elif TW <= 100000.0: + WD = ((((TW - 80000.0) * 0.04) + 2300.0) / PP) * 1.112 +else: + WD = ((((TW - 100000.0) * 0.05) + 3100.0) / PP) * 1.112 +result = -WD + + + + + + diff --git a/l10n_us_oh_hr_payroll/data/rules_2018.xml b/l10n_us_oh_hr_payroll/data/rules_2018.xml new file mode 100755 index 00000000..e2828c27 --- /dev/null +++ b/l10n_us_oh_hr_payroll/data/rules_2018.xml @@ -0,0 +1,104 @@ + + + + + + + + + Ohio Unemployment - Wages (2018) + OH_UNEMP_WAGES_2018 + python + result = (payslip.date_to[:4] == '2018') + code + +### +ytd = payslip.sum('OH_UNEMP_WAGES_2018', '2018-01-01', '2019-01-01') +ytd += contract.external_wages +remaining = 9500.0 - ytd +if remaining <= 0.0: + result = 0 +elif remaining < categories.GROSS: + result = remaining +else: + result = categories.GROSS + + + + + + + Ohio Unemployment (2018) + OH_UNEMP_2018 + python + result = (payslip.date_to[:4] == '2018') + code + +result_rate = -contract.oh_unemp_rate(2018) +result = categories.OH_UNEMP_WAGES + +# result_rate of 0 implies 100% due to bug +if result_rate == 0.0: + result = 0.0 + + + + + + + + + Ohio Income Withholding + OH_INC_WITHHOLD_2018 + python + result = (payslip.date_to[:4] == '2018') + code + +wages = categories.GROSS +allowances = contract.oh_income_allowances +schedule_pay = contract.schedule_pay +val = 0.00 + +PP = 0 +if 'weekly' == schedule_pay: + PP = 52 +elif 'bi-weekly' == schedule_pay: + PP = 26 +elif 'semi-monthly' == schedule_pay: # impossible + PP = 24 +elif 'monthly' == schedule_pay: + PP = 12 +elif 'quarterly' == schedule_pay: + PP = 4 +elif 'semi-annually' == schedule_pay: + PP = 2 +elif 'annually' == schedule_pay: + PP = 1 +else: + raise Exception('Invalid schedule_pay="' + schedule_pay + '" for OH Income Withholding calculation') + +# Algorithm from http://www.tax.ohio.gov/Portals/0/employer_withholding/August2015Rates/WTH_OptionalComputerFormula_073015.pdf +TW = (wages * PP) - (650 * allowances) +if TW <= 5000.0: + WD = ((TW * 0.005) / PP) * 1.112 +elif TW <= 10000.0: + WD = ((((TW - 5000.0) * 0.01) + 25.0) / PP) * 1.112 +elif TW <= 15000.0: + WD = ((((TW - 10000.0) * 0.02) + 75.0) / PP) * 1.112 +elif TW <= 20000.0: + WD = ((((TW - 15000.0) * 0.025) + 175.0) / PP) * 1.112 +elif TW <= 40000.0: + WD = ((((TW - 20000.0) * 0.03) + 300.0) / PP) * 1.112 +elif TW <= 80000.0: + WD = ((((TW - 40000.0) * 0.035) + 900.0) / PP) * 1.112 +elif TW <= 100000.0: + WD = ((((TW - 80000.0) * 0.04) + 2300.0) / PP) * 1.112 +else: + WD = ((((TW - 100000.0) * 0.05) + 3100.0) / PP) * 1.112 +result = -WD + + + + + + diff --git a/l10n_us_oh_hr_payroll/hr_payroll.py b/l10n_us_oh_hr_payroll/hr_payroll.py new file mode 100755 index 00000000..3f648563 --- /dev/null +++ b/l10n_us_oh_hr_payroll/hr_payroll.py @@ -0,0 +1,27 @@ +from odoo import models, fields, api + + +class USOHHrContract(models.Model): + _inherit = 'hr.contract' + + oh_income_allowances = fields.Integer(string='Ohio Income Allowances', default=0) + + @api.multi + def oh_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, 'oh_unemp_rate_' + str(year)): + return self.employee_id.company_id['oh_unemp_rate_' + str(year)] + + raise NotImplemented('Year (' + str(year) + ') Not implemented for US Ohio.') + + +class OHCompany(models.Model): + _inherit = 'res.company' + + # Defaults from :: https://jfs.ohio.gov/ouc/uctax/rates.stm + oh_unemp_rate_2016 = fields.Float(string="Ohio Unemployment Rate 2016", default=2.7) + oh_unemp_rate_2017 = fields.Float(string="Ohio Unemployment Rate 2017", default=2.7) + oh_unemp_rate_2018 = fields.Float(string="Ohio Unemployment Rate 2018", default=2.7) diff --git a/l10n_us_oh_hr_payroll/hr_payroll_view.xml b/l10n_us_oh_hr_payroll/hr_payroll_view.xml new file mode 100755 index 00000000..6e44deee --- /dev/null +++ b/l10n_us_oh_hr_payroll/hr_payroll_view.xml @@ -0,0 +1,33 @@ + + + + + res.company.form + res.company + 64 + + + + + + + + + + + + + hr.contract.form.inherit + hr.contract + 64 + + + + + + + + + + + diff --git a/l10n_us_oh_hr_payroll/tests/__init__.py b/l10n_us_oh_hr_payroll/tests/__init__.py new file mode 100755 index 00000000..71db8ace --- /dev/null +++ b/l10n_us_oh_hr_payroll/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +from . import test_us_oh_payslip_2016 +from . import test_us_oh_payslip_2017 +from . import test_us_oh_payslip_2018 diff --git a/l10n_us_oh_hr_payroll/tests/test_us_oh_payslip_2016.py b/l10n_us_oh_hr_payroll/tests/test_us_oh_payslip_2016.py new file mode 100755 index 00000000..bbf0713e --- /dev/null +++ b/l10n_us_oh_hr_payroll/tests/test_us_oh_payslip_2016.py @@ -0,0 +1,111 @@ +# -*- coding: utf-8 -*- + +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 TestUsOhPayslip(TestUsPayslip): + ### + # 2016 Taxes and Rates + ### + + def test_2016_taxes(self): + salary = 5000.0 + + ## tax maximums + OH_UNEMP_MAX_WAGE = 9000.0 + + ## For formula here + # http://www.tax.ohio.gov/Portals/0/employer_withholding/August2015Rates/WTH_OptionalComputerFormula_073015.pdf + TW = salary * 12 # = 60000 + WD = ((TW - 40000) * 0.035 + 900) / 12 * 1.112 + + + employee = self._createEmployee() + employee.company_id.oh_unemp_rate_2016 = 2.7 + + contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_oh_hr_payroll.hr_payroll_salary_structure_us_oh_employee')) + + ## tax rates + OH_UNEMP = contract.oh_unemp_rate(2016) / -100.0 + + self._log('2016 Ohio tax first payslip:') + payslip = self._createPayslip(employee, '2016-01-01', '2016-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['OH_UNEMP_WAGES'], salary) + self.assertPayrollEqual(cats['OH_UNEMP'], cats['OH_UNEMP_WAGES'] * OH_UNEMP) + self.assertPayrollEqual(cats['OH_INC_WITHHOLD'], -WD) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_oh_unemp_wages = OH_UNEMP_MAX_WAGE - salary if (OH_UNEMP_MAX_WAGE - 2*salary < salary) else salary + + self._log('2016 Ohio tax second payslip:') + payslip = self._createPayslip(employee, '2016-02-01', '2016-02-29') # 2016 is a leap year + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['OH_UNEMP_WAGES'], remaining_oh_unemp_wages) + self.assertPayrollEqual(cats['OH_UNEMP'], remaining_oh_unemp_wages * OH_UNEMP) + + + def test_2016_taxes_with_external(self): + salary = 5000.0 + external_wages = 6000.0 + + employee = self._createEmployee() + employee.company_id.oh_unemp_rate_2016 = 2.8 + + contract = self._createContract(employee, salary, external_wages=external_wages, + struct_id=self.ref('l10n_us_oh_hr_payroll.hr_payroll_salary_structure_us_oh_employee')) + ## tax maximums + OH_UNEMP_MAX_WAGE = 9000.0 + + ## tax rates + OH_UNEMP = contract.oh_unemp_rate(2016) / -100.0 + + self._log('2016 Ohio_external tax first payslip:') + payslip = self._createPayslip(employee, '2016-01-01', '2016-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['OH_UNEMP_WAGES'], OH_UNEMP_MAX_WAGE - external_wages) + self.assertPayrollEqual(cats['OH_UNEMP'], cats['OH_UNEMP_WAGES'] * OH_UNEMP) + + + def test_2016_taxes_with_state_exempt(self): + salary = 5000.0 + external_wages = 6000.0 + + employee = self._createEmployee() + employee.company_id.oh_unemp_rate_2016 = 2.9 + + contract = self._createContract(employee, salary, external_wages=external_wages, struct_id=self.ref( + 'l10n_us_oh_hr_payroll.hr_payroll_salary_structure_us_oh_employee'), futa_type=USHrContract.FUTA_TYPE_BASIC) + ## tax maximums + OH_UNEMP_MAX_WAGE = 9000.0 + + ## tax rates + OH_UNEMP = contract.oh_unemp_rate(2016) / -100.0 + + self.assertPayrollEqual(OH_UNEMP, 0.0) + + self._log('2016 Ohio exempt tax first payslip:') + payslip = self._createPayslip(employee, '2016-01-01', '2016-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['OH_UNEMP_WAGES'], OH_UNEMP_MAX_WAGE - external_wages) + self.assertPayrollEqual(cats['OH_UNEMP'], cats['OH_UNEMP_WAGES'] * OH_UNEMP) \ No newline at end of file diff --git a/l10n_us_oh_hr_payroll/tests/test_us_oh_payslip_2017.py b/l10n_us_oh_hr_payroll/tests/test_us_oh_payslip_2017.py new file mode 100755 index 00000000..3d94fd6f --- /dev/null +++ b/l10n_us_oh_hr_payroll/tests/test_us_oh_payslip_2017.py @@ -0,0 +1,108 @@ +# -*- coding: utf-8 -*- + +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 TestUsOhPayslip(TestUsPayslip): + ### + # Taxes and Rates + ### + OH_UNEMP_MAX_WAGE = 9000.0 + + def test_2017_taxes(self): + salary = 5000.0 + + # For formula here + # http://www.tax.ohio.gov/Portals/0/employer_withholding/August2015Rates/WTH_OptionalComputerFormula_073015.pdf + tw = salary * 12 # = 60000 + wd = ((tw - 40000) * 0.035 + 900) / 12 * 1.112 + + employee = self._createEmployee() + employee.company_id.oh_unemp_rate_2017 = 2.7 + + contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_oh_hr_payroll.hr_payroll_salary_structure_us_oh_employee')) + + # tax rates + oh_unemp = contract.oh_unemp_rate(2017) / -100.0 + + self._log('2016 Ohio tax last payslip:') + payslip = self._createPayslip(employee, '2016-12-01', '2016-12-31') + payslip.compute_sheet() + process_payslip(payslip) + + self._log('2017 Ohio tax first payslip:') + payslip = self._createPayslip(employee, '2017-01-01', '2017-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['OH_UNEMP_WAGES'], salary) + self.assertPayrollEqual(cats['OH_UNEMP'], cats['OH_UNEMP_WAGES'] * oh_unemp) + self.assertPayrollEqual(cats['OH_INC_WITHHOLD'], -wd) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_oh_unemp_wages = self.OH_UNEMP_MAX_WAGE - salary if (self.OH_UNEMP_MAX_WAGE - 2*salary < salary) \ + else salary + + self._log('2017 Ohio tax second payslip:') + payslip = self._createPayslip(employee, '2017-02-01', '2017-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['OH_UNEMP_WAGES'], remaining_oh_unemp_wages) + self.assertPayrollEqual(cats['OH_UNEMP'], remaining_oh_unemp_wages * oh_unemp) + + def test_2017_taxes_with_external(self): + salary = 5000.0 + external_wages = 6000.0 + + employee = self._createEmployee() + employee.company_id.oh_unemp_rate_2017 = 2.8 + + contract = self._createContract(employee, salary, external_wages=external_wages, + struct_id=self.ref('l10n_us_oh_hr_payroll.hr_payroll_salary_structure_us_oh_employee')) + + # tax rates + oh_unemp = contract.oh_unemp_rate(2017) / -100.0 + + self._log('2017 Ohio_external tax first payslip:') + payslip = self._createPayslip(employee, '2017-01-01', '2017-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['OH_UNEMP_WAGES'], self.OH_UNEMP_MAX_WAGE - external_wages) + self.assertPayrollEqual(cats['OH_UNEMP'], cats['OH_UNEMP_WAGES'] * oh_unemp) + + def test_2017_taxes_with_state_exempt(self): + salary = 5000.0 + external_wages = 6000.0 + + employee = self._createEmployee() + employee.company_id.oh_unemp_rate_2017 = 2.9 + + contract = self._createContract(employee, salary, external_wages=external_wages, struct_id=self.ref( + 'l10n_us_oh_hr_payroll.hr_payroll_salary_structure_us_oh_employee'), futa_type=USHrContract.FUTA_TYPE_BASIC) + + # tax rates + oh_unemp = contract.oh_unemp_rate(2017) / -100.0 + + self.assertPayrollEqual(oh_unemp, 0.0) + + self._log('2017 Ohio exempt tax first payslip:') + payslip = self._createPayslip(employee, '2017-01-01', '2017-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['OH_UNEMP_WAGES'], self.OH_UNEMP_MAX_WAGE - external_wages) + self.assertPayrollEqual(cats['OH_UNEMP'], cats['OH_UNEMP_WAGES'] * oh_unemp) diff --git a/l10n_us_oh_hr_payroll/tests/test_us_oh_payslip_2018.py b/l10n_us_oh_hr_payroll/tests/test_us_oh_payslip_2018.py new file mode 100755 index 00000000..dbf05fc5 --- /dev/null +++ b/l10n_us_oh_hr_payroll/tests/test_us_oh_payslip_2018.py @@ -0,0 +1,108 @@ +# -*- coding: utf-8 -*- + +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 TestUsOhPayslip(TestUsPayslip): + ### + # Taxes and Rates + ### + OH_UNEMP_MAX_WAGE = 9500.0 + + def test_2018_taxes(self): + salary = 5000.0 + + # For formula here + # http://www.tax.ohio.gov/Portals/0/employer_withholding/August2015Rates/WTH_OptionalComputerFormula_073015.pdf + tw = salary * 12 # = 60000 + wd = ((tw - 40000) * 0.035 + 900) / 12 * 1.112 + + employee = self._createEmployee() + employee.company_id.oh_unemp_rate_2018 = 2.7 + + contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_oh_hr_payroll.hr_payroll_salary_structure_us_oh_employee')) + + # tax rates + oh_unemp = contract.oh_unemp_rate(2018) / -100.0 + + self._log('2016 Ohio tax last payslip:') + payslip = self._createPayslip(employee, '2016-12-01', '2016-12-31') + payslip.compute_sheet() + process_payslip(payslip) + + self._log('2018 Ohio tax first payslip:') + payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['OH_UNEMP_WAGES'], salary) + self.assertPayrollEqual(cats['OH_UNEMP'], cats['OH_UNEMP_WAGES'] * oh_unemp) + self.assertPayrollEqual(cats['OH_INC_WITHHOLD'], -wd) + + process_payslip(payslip) + + # Make a new payslip, this one will have maximums + + remaining_oh_unemp_wages = self.OH_UNEMP_MAX_WAGE - salary if (self.OH_UNEMP_MAX_WAGE - 2*salary < salary) \ + else salary + + self._log('2018 Ohio tax second payslip:') + payslip = self._createPayslip(employee, '2018-02-01', '2018-02-28') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['OH_UNEMP_WAGES'], remaining_oh_unemp_wages) + self.assertPayrollEqual(cats['OH_UNEMP'], remaining_oh_unemp_wages * oh_unemp) + + def test_2018_taxes_with_external(self): + salary = 5000.0 + external_wages = 6000.0 + + employee = self._createEmployee() + employee.company_id.oh_unemp_rate_2018 = 2.8 + + contract = self._createContract(employee, salary, external_wages=external_wages, + struct_id=self.ref('l10n_us_oh_hr_payroll.hr_payroll_salary_structure_us_oh_employee')) + + # tax rates + oh_unemp = contract.oh_unemp_rate(2018) / -100.0 + + self._log('2018 Ohio_external tax first payslip:') + payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['OH_UNEMP_WAGES'], self.OH_UNEMP_MAX_WAGE - external_wages) + self.assertPayrollEqual(cats['OH_UNEMP'], cats['OH_UNEMP_WAGES'] * oh_unemp) + + def test_2018_taxes_with_state_exempt(self): + salary = 5000.0 + external_wages = 6000.0 + + employee = self._createEmployee() + employee.company_id.oh_unemp_rate_2018 = 2.9 + + contract = self._createContract(employee, salary, external_wages=external_wages, struct_id=self.ref( + 'l10n_us_oh_hr_payroll.hr_payroll_salary_structure_us_oh_employee'), futa_type=USHrContract.FUTA_TYPE_BASIC) + + # tax rates + oh_unemp = contract.oh_unemp_rate(2018) / -100.0 + + self.assertPayrollEqual(oh_unemp, 0.0) + + self._log('2018 Ohio exempt tax first payslip:') + payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31') + + payslip.compute_sheet() + + cats = self._getCategories(payslip) + + self.assertPayrollEqual(cats['OH_UNEMP_WAGES'], self.OH_UNEMP_MAX_WAGE - external_wages) + self.assertPayrollEqual(cats['OH_UNEMP'], cats['OH_UNEMP_WAGES'] * oh_unemp)