mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
IMP l10n_us_hr_payroll Refactor SUTA tests into generic test. (Reworked Florida 2020)
This commit is contained in:
@@ -3,9 +3,11 @@
|
|||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from sys import float_info as sys_float_info
|
from sys import float_info as sys_float_info
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
from odoo.tests import common
|
from odoo.tests import common
|
||||||
from odoo.tools.float_utils import float_round as odoo_float_round
|
from odoo.tools.float_utils import float_round as odoo_float_round
|
||||||
|
from odoo.addons.l10n_us_hr_payroll.models.hr_contract import USHRContract
|
||||||
|
|
||||||
|
|
||||||
def process_payslip(payslip):
|
def process_payslip(payslip):
|
||||||
@@ -166,3 +168,58 @@ class TestUsPayslip(common.TransactionCase):
|
|||||||
], limit=1)
|
], limit=1)
|
||||||
cache[code] = us_state
|
cache[code] = us_state
|
||||||
return us_state
|
return us_state
|
||||||
|
|
||||||
|
def _test_er_suta(self, state_code, rate, date, wage_base=None, **extra_contract):
|
||||||
|
if wage_base:
|
||||||
|
# Slightly larger than 1/2 the wage_base
|
||||||
|
wage = round(wage_base / 2.0) + 100.0
|
||||||
|
self.assertTrue((2 * wage) > wage_base, 'Granularity of wage_base too low.')
|
||||||
|
else:
|
||||||
|
wage = 1000.0
|
||||||
|
|
||||||
|
employee = self._createEmployee()
|
||||||
|
contract = self._createContract(employee,
|
||||||
|
wage=wage,
|
||||||
|
state_id=self.get_us_state(state_code),
|
||||||
|
**extra_contract)
|
||||||
|
|
||||||
|
rate = -rate / 100.0 # Assumed passed as percent positive
|
||||||
|
|
||||||
|
# Tests
|
||||||
|
payslip = self._createPayslip(employee, date, date + timedelta(days=30))
|
||||||
|
|
||||||
|
# Test exemptions
|
||||||
|
contract.us_payroll_config_id.fed_940_type = USHRContract.FUTA_TYPE_EXEMPT
|
||||||
|
payslip.compute_sheet()
|
||||||
|
cats = self._getCategories(payslip)
|
||||||
|
self.assertPayrollEqual(cats.get('ER_US_SUTA', 0.0), 0.0)
|
||||||
|
|
||||||
|
contract.us_payroll_config_id.fed_940_type = USHRContract.FUTA_TYPE_BASIC
|
||||||
|
payslip.compute_sheet()
|
||||||
|
cats = self._getCategories(payslip)
|
||||||
|
self.assertPayrollEqual(cats.get('ER_US_SUTA', 0.0), 0.0)
|
||||||
|
|
||||||
|
# Test Normal
|
||||||
|
contract.us_payroll_config_id.fed_940_type = USHRContract.FUTA_TYPE_NORMAL
|
||||||
|
payslip.compute_sheet()
|
||||||
|
cats = self._getCategories(payslip)
|
||||||
|
self.assertPayrollEqual(cats.get('ER_US_SUTA', 0.0), wage * rate)
|
||||||
|
|
||||||
|
if wage_base:
|
||||||
|
process_payslip(payslip)
|
||||||
|
|
||||||
|
remaining_unemp_wages = wage_base - wage
|
||||||
|
self.assertTrue((remaining_unemp_wages * rate) <= 0.01) # less than 0.01 because rate is negative
|
||||||
|
payslip = self._createPayslip(employee, date + timedelta(days=31), date + timedelta(days=60))
|
||||||
|
payslip.compute_sheet()
|
||||||
|
cats = self._getCategories(payslip)
|
||||||
|
self.assertPayrollEqual(cats.get('ER_US_SUTA', 0.0), remaining_unemp_wages * rate)
|
||||||
|
|
||||||
|
# As if they were paid once already, so the first "two payslips" would remove all of the tax obligation
|
||||||
|
# 1 wage - Payslip (confirmed)
|
||||||
|
# 1 wage - external_wages
|
||||||
|
# 1 wage - current Payslip
|
||||||
|
contract.external_wages = wage
|
||||||
|
payslip.compute_sheet()
|
||||||
|
cats = self._getCategories(payslip)
|
||||||
|
self.assertPayrollEqual(cats.get('ER_US_SUTA', 0.0), 0.0)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from .common import TestUsPayslip, process_payslip
|
from datetime import date
|
||||||
from odoo.addons.l10n_us_hr_payroll.models.hr_contract import USHRContract
|
from .common import TestUsPayslip
|
||||||
|
|
||||||
|
|
||||||
class TestUsFlPayslip(TestUsPayslip):
|
class TestUsFlPayslip(TestUsPayslip):
|
||||||
@@ -7,76 +7,8 @@ class TestUsFlPayslip(TestUsPayslip):
|
|||||||
# 2020 Taxes and Rates
|
# 2020 Taxes and Rates
|
||||||
###
|
###
|
||||||
FL_UNEMP_MAX_WAGE = 7000.0
|
FL_UNEMP_MAX_WAGE = 7000.0
|
||||||
FL_UNEMP = -2.7 / 100.0
|
FL_UNEMP = 2.7
|
||||||
|
|
||||||
def test_2020_taxes(self):
|
def test_2020_taxes(self):
|
||||||
salary = 5000.0
|
# Only has state unemployment
|
||||||
|
self._test_er_suta('FL', self.FL_UNEMP, date(2020, 1, 1), wage_base=self.FL_UNEMP_MAX_WAGE)
|
||||||
employee = self._createEmployee()
|
|
||||||
contract = self._createContract(employee,
|
|
||||||
wage=salary,
|
|
||||||
state_id=self.get_us_state('FL'))
|
|
||||||
|
|
||||||
self._log('2020 Florida tax first payslip:')
|
|
||||||
payslip = self._createPayslip(employee, '2020-01-01', '2020-01-31')
|
|
||||||
|
|
||||||
payslip.compute_sheet()
|
|
||||||
|
|
||||||
cats = self._getCategories(payslip)
|
|
||||||
|
|
||||||
self.assertPayrollEqual(cats['ER_US_SUTA'], salary * self.FL_UNEMP)
|
|
||||||
|
|
||||||
process_payslip(payslip)
|
|
||||||
|
|
||||||
# Make a new payslip, this one will have maximums
|
|
||||||
|
|
||||||
remaining_fl_unemp_wages = self.FL_UNEMP_MAX_WAGE - salary if (self.FL_UNEMP_MAX_WAGE - 2*salary < salary) \
|
|
||||||
else salary
|
|
||||||
|
|
||||||
self._log('2020 Florida tax second payslip:')
|
|
||||||
payslip = self._createPayslip(employee, '2020-02-01', '2020-02-28')
|
|
||||||
|
|
||||||
payslip.compute_sheet()
|
|
||||||
|
|
||||||
cats = self._getCategories(payslip)
|
|
||||||
|
|
||||||
self.assertPayrollEqual(cats['ER_US_SUTA'], remaining_fl_unemp_wages * self.FL_UNEMP)
|
|
||||||
|
|
||||||
def test_2020_taxes_with_external(self):
|
|
||||||
salary = 5000.0
|
|
||||||
external_wages = 6000.0
|
|
||||||
|
|
||||||
employee = self._createEmployee()
|
|
||||||
contract = self._createContract(employee,
|
|
||||||
wage=salary,
|
|
||||||
external_wages=external_wages,
|
|
||||||
state_id=self.get_us_state('FL'))
|
|
||||||
|
|
||||||
self._log('2020 Forida_external tax first payslip:')
|
|
||||||
payslip = self._createPayslip(employee, '2020-01-01', '2020-01-31')
|
|
||||||
|
|
||||||
payslip.compute_sheet()
|
|
||||||
|
|
||||||
cats = self._getCategories(payslip)
|
|
||||||
|
|
||||||
self.assertPayrollEqual(cats['ER_US_SUTA'], (self.FL_UNEMP_MAX_WAGE - external_wages) * self.FL_UNEMP)
|
|
||||||
|
|
||||||
def test_2020_taxes_with_state_exempt(self):
|
|
||||||
salary = 5000.0
|
|
||||||
external_wages = 6000.0
|
|
||||||
|
|
||||||
employee = self._createEmployee()
|
|
||||||
contract = self._createContract(employee,
|
|
||||||
wage=salary,
|
|
||||||
external_wages=external_wages,
|
|
||||||
futa_type=USHRContract.FUTA_TYPE_BASIC,
|
|
||||||
state_id=self.get_us_state('FL'))
|
|
||||||
|
|
||||||
self._log('2020 Forida_external tax first payslip:')
|
|
||||||
payslip = self._createPayslip(employee, '2020-01-01', '2020-01-31')
|
|
||||||
|
|
||||||
payslip.compute_sheet()
|
|
||||||
|
|
||||||
cats = self._getCategories(payslip)
|
|
||||||
|
|
||||||
self.assertPayrollEqual(cats.get('ER_US_SUTA', 0.0), 0.0)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user