mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Merge branch 'new/13.0/l10n_us_hr_payroll' into '13.0-test'
new/13.0/l10n_us_hr_payroll into 13.0-test See merge request hibou-io/hibou-odoo/suite!214
This commit is contained in:
@@ -25,6 +25,7 @@ United States of America - Payroll Rules.
|
||||
'data/federal/fed_941_fica_rules.xml',
|
||||
'data/federal/fed_941_fit_parameters.xml',
|
||||
'data/federal/fed_941_fit_rules.xml',
|
||||
'data/state/fl_florida.xml',
|
||||
'views/hr_contract_views.xml',
|
||||
'views/us_payroll_config_views.xml',
|
||||
],
|
||||
|
||||
@@ -17,4 +17,16 @@
|
||||
]"/>
|
||||
</record>
|
||||
|
||||
<!-- State Unemployment -->
|
||||
<record id="hr_payroll_category_ee_us_suta" model="hr.salary.rule.category">
|
||||
<field name="name">EE: State Unemployment SUTA</field>
|
||||
<field name="code">EE_US_SUTA</field>
|
||||
<field name="parent_id" ref="hr_payroll.DED"/>
|
||||
</record>
|
||||
<record id="hr_payroll_category_er_us_suta" model="hr.salary.rule.category">
|
||||
<field name="name">ER: State Unemployment SUTA</field>
|
||||
<field name="code">ER_US_SUTA</field>
|
||||
<field name="parent_id" ref="hr_payroll.COMP"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
63
l10n_us_hr_payroll/data/state/fl_florida.xml
Normal file
63
l10n_us_hr_payroll/data/state/fl_florida.xml
Normal file
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<!-- Wage Base -->
|
||||
<record id="rule_parameter_us_fl_suta_wage_base" model="hr.rule.parameter">
|
||||
<field name="name">US FL Florida SUTA Wage Base</field>
|
||||
<field name="code">us_fl_suta_wage_base</field>
|
||||
<field name="country_id" ref="base.us"/>
|
||||
</record>
|
||||
<data noupdate="1">
|
||||
<record id="rule_parameter_us_fl_suta_wage_base_2019" model="hr.rule.parameter.value">
|
||||
<field name="parameter_value">7000.00</field>
|
||||
<field name="rule_parameter_id" ref="rule_parameter_us_fl_suta_wage_base"/>
|
||||
<field name="date_from" eval="datetime(2019, 1, 1).date()"/>
|
||||
</record>
|
||||
<record id="rule_parameter_us_fl_suta_wage_base_2020" model="hr.rule.parameter.value">
|
||||
<field name="parameter_value">7000.00</field>
|
||||
<field name="rule_parameter_id" ref="rule_parameter_us_fl_suta_wage_base"/>
|
||||
<field name="date_from" eval="datetime(2020, 1, 1).date()"/>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
<!-- Rate -->
|
||||
<record id="rule_parameter_us_fl_suta_rate" model="hr.rule.parameter">
|
||||
<field name="name">US FL Florida SUTA Rate</field>
|
||||
<field name="code">us_fl_suta_rate</field>
|
||||
<field name="country_id" ref="base.us"/>
|
||||
</record>
|
||||
<data noupdate="1">
|
||||
<record id="rule_parameter_us_fl_suta_rate_2019" model="hr.rule.parameter.value">
|
||||
<field name="parameter_value">2.7</field>
|
||||
<field name="rule_parameter_id" ref="rule_parameter_us_fl_suta_rate"/>
|
||||
<field name="date_from" eval="datetime(2019, 1, 1).date()"/>
|
||||
</record>
|
||||
<record id="rule_parameter_us_fl_suta_rate_2020" model="hr.rule.parameter.value">
|
||||
<field name="parameter_value">2.7</field>
|
||||
<field name="rule_parameter_id" ref="rule_parameter_us_fl_suta_rate"/>
|
||||
<field name="date_from" eval="datetime(2020, 1, 1).date()"/>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
<!-- Partners and Contribution Registers -->
|
||||
<record id="res_partner_us_fl_dor" model="res.partner">
|
||||
<field name="name">US Florida - Department of Revenue</field>
|
||||
</record>
|
||||
|
||||
<!-- Categories -->
|
||||
|
||||
<!-- Rules -->
|
||||
<record id="hr_payroll_rule_er_us_fl_suta" model="hr.salary.rule">
|
||||
<field name="sequence" eval="450"/>
|
||||
<field name="struct_id" ref="hr_payroll_structure"/>
|
||||
<field name="category_id" ref="hr_payroll_category_er_us_suta"/>
|
||||
<field name="name">ER: US FL Florida State Unemployment (RT-6)</field>
|
||||
<field name="code">ER_US_FL_SUTA</field>
|
||||
<field name="condition_select">python</field>
|
||||
<field name="condition_python">result, _ = general_state_unemployment(payslip, categories, worked_days, inputs, wage_base='us_fl_suta_wage_base', rate='us_fl_suta_rate', state_code='FL')</field>
|
||||
<field name="amount_select">code</field>
|
||||
<field name="amount_python_compute">result, result_rate = general_state_unemployment(payslip, categories, worked_days, inputs, wage_base='us_fl_suta_wage_base', rate='us_fl_suta_rate', state_code='FL')</field>
|
||||
<field name="partner_id" ref="res_partner_us_fl_dor"/>
|
||||
<field name="appears_on_payslip" eval="False"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -9,6 +9,7 @@ from .federal.fed_941 import ee_us_941_fica_ss, \
|
||||
er_us_941_fica_ss, \
|
||||
er_us_941_fica_m, \
|
||||
ee_us_941_fit
|
||||
from .state.general import general_state_unemployment
|
||||
|
||||
|
||||
class HRPayslip(models.Model):
|
||||
@@ -37,6 +38,7 @@ class HRPayslip(models.Model):
|
||||
'er_us_941_fica_ss': er_us_941_fica_ss,
|
||||
'er_us_941_fica_m': er_us_941_fica_m,
|
||||
'ee_us_941_fit': ee_us_941_fit,
|
||||
'general_state_unemployment': general_state_unemployment,
|
||||
})
|
||||
return res
|
||||
|
||||
|
||||
1
l10n_us_hr_payroll/models/state/__init__.py
Normal file
1
l10n_us_hr_payroll/models/state/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
85
l10n_us_hr_payroll/models/state/general.py
Normal file
85
l10n_us_hr_payroll/models/state/general.py
Normal file
@@ -0,0 +1,85 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
# import logging
|
||||
# _logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def general_state_unemployment(payslip, categories, worked_days, inputs, wage_base=None, wage_start=None, rate=None, state_code=None):
|
||||
"""
|
||||
Returns SUTA eligible wage and rate.
|
||||
WAGE = GROSS - WAGE_US_940_FUTA_EXEMPT
|
||||
|
||||
The contract's `futa_type` determines if SUTA should be collected.
|
||||
|
||||
Function parameters:
|
||||
wage_base, wage_start, rate can either be strings (rule_parameters) or floats
|
||||
|
||||
:return: result, result_rate (wage, percent)
|
||||
"""
|
||||
|
||||
if state_code != payslip.contract_id.us_payroll_config_value('state_code'):
|
||||
return 0.0, 0.0
|
||||
|
||||
# Determine Eligible.
|
||||
if payslip.contract_id.futa_type in (payslip.contract_id.FUTA_TYPE_EXEMPT, payslip.contract_id.FUTA_TYPE_BASIC):
|
||||
return 0.0, 0.0
|
||||
|
||||
# Resolve parameters. On exception, return (probably missing a year, would rather not have exception)
|
||||
if wage_base and isinstance(wage_base, str):
|
||||
try:
|
||||
wage_base = payslip.rule_parameter(wage_base)
|
||||
except (KeyError, UserError):
|
||||
return 0.0, 0.0
|
||||
|
||||
if wage_start and isinstance(wage_start, str):
|
||||
try:
|
||||
wage_start = payslip.rule_parameter(wage_start)
|
||||
except (KeyError, UserError):
|
||||
return 0.0, 0.0
|
||||
|
||||
if rate and isinstance(rate, str):
|
||||
try:
|
||||
rate = payslip.rule_parameter(rate)
|
||||
except (KeyError, UserError):
|
||||
return 0.0, 0.0
|
||||
|
||||
if not rate:
|
||||
return 0.0, 0.0
|
||||
else:
|
||||
# Rate assumed positive percentage!
|
||||
rate = -rate
|
||||
|
||||
# Determine Wage
|
||||
year = payslip.dict.get_year()
|
||||
ytd_wage = payslip.sum_category('GROSS', str(year) + '-01-01', str(year + 1) + '-01-01')
|
||||
ytd_wage -= payslip.sum_category('WAGE_US_940_FUTA_EXEMPT', str(year) + '-01-01', str(year + 1) + '-01-01')
|
||||
ytd_wage += payslip.contract_id.external_wages
|
||||
|
||||
wage = categories.GROSS - categories.WAGE_US_940_FUTA_EXEMPT
|
||||
#_logger.warn('ytd_wage: ' + str(ytd_wage) + ' wage: ' + str(wage))
|
||||
|
||||
if wage_base:
|
||||
remaining = wage_base - ytd_wage
|
||||
if remaining < 0.0:
|
||||
result = 0.0
|
||||
elif remaining < wage:
|
||||
result = remaining
|
||||
else:
|
||||
result = wage
|
||||
|
||||
#_logger.warn(' wage_base method result: ' + str(result) + ' rate: ' + str(rate))
|
||||
return result, rate
|
||||
if wage_start:
|
||||
if ytd_wage >= wage_start:
|
||||
#_logger.warn(' wage_start 1 method result: ' + str(wage) + ' rate: ' + str(rate))
|
||||
return wage, rate
|
||||
if ytd_wage + wage <= wage_start:
|
||||
#_logger.warn(' wage_start 2 method result: ' + str(0.0) + ' rate: ' + str(0.0))
|
||||
return 0.0, 0.0
|
||||
#_logger.warn(' wage_start 3 method result: ' + str((wage - (wage_start - ytd_wage))) + ' rate: ' + str(rate))
|
||||
return (wage - (wage_start - ytd_wage)), rate
|
||||
|
||||
# If the wage doesn't have a start or a base
|
||||
#_logger.warn(' basic result: ' + str(wage) + ' rate: ' + str(rate))
|
||||
return wage, rate
|
||||
@@ -14,6 +14,7 @@ class HRContractUSPayrollConfig(models.Model):
|
||||
name = fields.Char(string="Description")
|
||||
employee_id = fields.Many2one('hr.employee', string="Employee", required=True)
|
||||
state_id = fields.Many2one('res.country.state', string="Applied State")
|
||||
state_code = fields.Char(related='state_id.code')
|
||||
|
||||
fed_940_type = fields.Selection([
|
||||
(FUTA_TYPE_EXEMPT, 'Exempt (0%)'),
|
||||
|
||||
@@ -3,3 +3,6 @@
|
||||
from . import common
|
||||
from . import test_us_payslip_2019
|
||||
from . import test_us_payslip_2020
|
||||
|
||||
from . import test_us_fl_florida_payslip_2019
|
||||
from . import test_us_fl_florida_payslip_2020
|
||||
|
||||
@@ -61,6 +61,10 @@ class TestUsPayslip(common.TransactionCase):
|
||||
'employee_id': employee.id,
|
||||
}
|
||||
|
||||
# Backwards compatability with 'futa_type'
|
||||
if 'futa_type' in kwargs:
|
||||
kwargs['fed_940_type'] = kwargs['futa_type']
|
||||
|
||||
for key, val in kwargs.items():
|
||||
# Assume any Odoo object is in a Many2one
|
||||
if hasattr(val, 'id'):
|
||||
@@ -148,3 +152,17 @@ class TestUsPayslip(common.TransactionCase):
|
||||
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-14')
|
||||
|
||||
payslip.compute_sheet()
|
||||
|
||||
def get_us_state(self, code, cache={}):
|
||||
country_key = 'US_COUNTRY'
|
||||
if code in cache:
|
||||
return cache[code]
|
||||
if country_key not in cache:
|
||||
cache[country_key] = self.env.ref('base.us')
|
||||
us_country = cache[country_key]
|
||||
us_state = self.env['res.country.state'].search([
|
||||
('country_id', '=', us_country.id),
|
||||
('code', '=', code),
|
||||
], limit=1)
|
||||
cache[code] = us_state
|
||||
return us_state
|
||||
|
||||
82
l10n_us_hr_payroll/tests/test_us_fl_florida_payslip_2019.py
Executable file
82
l10n_us_hr_payroll/tests/test_us_fl_florida_payslip_2019.py
Executable file
@@ -0,0 +1,82 @@
|
||||
from .common import TestUsPayslip, process_payslip
|
||||
from odoo.addons.l10n_us_hr_payroll.models.hr_contract import USHRContract
|
||||
|
||||
|
||||
class TestUsFlPayslip(TestUsPayslip):
|
||||
###
|
||||
# 2019 Taxes and Rates
|
||||
###
|
||||
FL_UNEMP_MAX_WAGE = 7000.0
|
||||
FL_UNEMP = -2.7 / 100.0
|
||||
|
||||
def test_2019_taxes(self):
|
||||
salary = 5000.0
|
||||
|
||||
employee = self._createEmployee()
|
||||
contract = self._createContract(employee,
|
||||
wage=salary,
|
||||
state_id=self.get_us_state('FL'))
|
||||
|
||||
self._log('2019 Florida tax first payslip:')
|
||||
payslip = self._createPayslip(employee, '2019-01-01', '2019-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('2019 Florida tax second payslip:')
|
||||
payslip = self._createPayslip(employee, '2019-02-01', '2019-02-28')
|
||||
|
||||
payslip.compute_sheet()
|
||||
|
||||
cats = self._getCategories(payslip)
|
||||
|
||||
self.assertPayrollEqual(cats['ER_US_SUTA'], remaining_fl_unemp_wages * self.FL_UNEMP)
|
||||
|
||||
def test_2019_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('2019 Forida_external tax first payslip:')
|
||||
payslip = self._createPayslip(employee, '2019-01-01', '2019-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_2019_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('2019 Forida_external tax first payslip:')
|
||||
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
|
||||
|
||||
payslip.compute_sheet()
|
||||
|
||||
cats = self._getCategories(payslip)
|
||||
|
||||
self.assertPayrollEqual(cats.get('ER_US_SUTA', 0.0), 0.0)
|
||||
82
l10n_us_hr_payroll/tests/test_us_fl_florida_payslip_2020.py
Executable file
82
l10n_us_hr_payroll/tests/test_us_fl_florida_payslip_2020.py
Executable file
@@ -0,0 +1,82 @@
|
||||
from .common import TestUsPayslip, process_payslip
|
||||
from odoo.addons.l10n_us_hr_payroll.models.hr_contract import USHRContract
|
||||
|
||||
|
||||
class TestUsFlPayslip(TestUsPayslip):
|
||||
###
|
||||
# 2020 Taxes and Rates
|
||||
###
|
||||
FL_UNEMP_MAX_WAGE = 7000.0
|
||||
FL_UNEMP = -2.7 / 100.0
|
||||
|
||||
def test_2020_taxes(self):
|
||||
salary = 5000.0
|
||||
|
||||
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)
|
||||
@@ -40,6 +40,10 @@
|
||||
<field name="fed_941_fit_w4_deductions" string="Deductions"/>
|
||||
<field name="fed_941_fit_w4_additional_withholding" string="Additional Withholding"/>
|
||||
</group>
|
||||
|
||||
<group name="state_fl_florida" string="FL Florida" attrs="{'invisible':[('state_id', '!=', %(base.state_us_10)s)]}">
|
||||
<p colspan="2"><h3>No additional fields.</h3></p>
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user