Merge branch 'new/11.0/l10n_us_mi_hr_payroll' into 11.0-test

This commit is contained in:
Jared Kipe
2019-07-19 07:19:59 -07:00
11 changed files with 519 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,28 @@
{
'name': 'USA - Michigan - Payroll',
'author': 'Hibou Corp. <hello@hibou.io>',
'license': 'AGPL-3',
'category': 'Localization',
'depends': ['l10n_us_hr_payroll'],
'version': '11.0.2019.0.0',
'description': """
USA::Michigan Payroll Rules.
==================================
* Contribution register and partner for Michigan Unemployment Insurance Agency - Unemployment
* Contribution register and partner for Michigan Department of Treasury - Income Tax Withholding
* Contract level Michigan Exemptions
* Company level Michigan Unemployment Rate
""",
'auto_install': False,
'website': 'https://hibou.io/',
'data': [
'views/hr_payroll_views.xml',
'data/base.xml',
'data/rates.xml',
'data/rules.xml',
'data/final.xml',
],
'installable': True
}

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- CONTRIBUTION REGISTERS -->
<record id="res_partner_mi_uia_unemp" model="res.partner">
<field name="name">Michigan Unemployment Insurance Agency - Unemployment Tax</field>
<field name="supplier">1</field>
<field eval="0" name="customer"/>
</record>
<record id="res_partner_mi_dot_withhold" model="res.partner">
<field name="name">Michigan Department of Treasury - Income Tax Withholding</field>
<field name="supplier">1</field>
<field eval="0" name="customer"/>
</record>
<record id="contrib_register_mi_uia_unemp" model="hr.contribution.register">
<field name="name">Michigan Unemployment</field>
<field name="note">Michigan Unemployment Insurance Agency - Unemployment</field>
<field name="partner_id" ref="res_partner_mi_uia_unemp"/>
</record>
<record id="contrib_register_mi_dot_withhold" model="hr.contribution.register">
<field name="name">Michigan Income Tax Withholding</field>
<field name="note">Michigan Department of Treasury - Income Tax Withholding</field>
<field name="partner_id" ref="res_partner_mi_dot_withhold"/>
</record>
<!-- HR SALARY RULE CATEGORIES-->
<record id="hr_payroll_mi_unemp_wages" model="hr.salary.rule.category">
<field name="name">Wage: US-MI Unemployment</field>
<field name="code">WAGE_US_MI_UNEMP</field>
</record>
<record id="hr_payroll_mi_unemp" model="hr.salary.rule.category">
<field name="name">ER: US-MI Unemployment</field>
<field name="code">ER_US_MI_UNEMP</field>
<field name="parent_id" ref="hr_payroll.COMP"/>
</record>
<record id="hr_payroll_mi_income_withhold" model="hr.salary.rule.category">
<field name="name">EE: US-MI Income Tax Withholding</field>
<field name="code">EE_US_MI_INC_WITHHOLD</field>
<field name="parent_id" ref="hr_payroll.DED"/>
</record>
</odoo>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- HR PAYROLL STRUCTURE -->
<record id="hr_payroll_salary_structure_us_mi_employee" model="hr.payroll.structure">
<field name="code">US_MI_EMP</field>
<field name="name">USA Michigan Employee</field>
<field eval="[(6, 0, [
ref('hr_payroll_rules_mi_unemp_wages'),
ref('hr_payroll_rules_mi_unemp'),
ref('hr_payroll_rules_mi_inc_withhold'),
])]" name="rule_ids"/>
<field name="company_id" ref="base.main_company"/>
<field name="parent_id" ref="l10n_us_hr_payroll.hr_payroll_salary_structure_us_employee"/>
</record>
</odoo>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="hr_payroll_rates_mi_unemp" model="hr.payroll.rate">
<field name="name">US MI Unemployment</field>
<field name="code">US_MI_UNEMP</field>
<field name="rate">6</field>
<field name="date_from">2019-01-01</field>
<field name="wage_limit_year" eval="9000"/>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- HR SALARY RULES-->
<record id="hr_payroll_rules_mi_unemp_wages" model="hr.salary.rule">
<field name="sequence" eval="423"/>
<field name="category_id" ref="hr_payroll_mi_unemp_wages"/>
<field name="name">Wage: US-MI Unemployment</field>
<field name="code">WAGE_US_MI_UNEMP</field>
<field name="condition_select">python</field>
<field name="condition_python">result = (contract.futa_type != contract.FUTA_TYPE_BASIC)</field>
<field name="amount_select">code</field>
<field name="amount_python_compute">
rate = payslip.dict.get_rate('US_MI_UNEMP')
year = int(payslip.dict.date_to[:4])
ytd = payslip.sum('WAGE_US_MI_UNEMP', str(year) + '-01-01', str(year+1) + '-01-01')
ytd += contract.external_wages
remaining = rate.wage_limit_year - ytd
if remaining &lt;= 0.0:
result = 0
elif remaining &lt; categories.BASIC:
result = remaining
else:
result = categories.BASIC
</field>
<field name="appears_on_payslip" eval="False"/>
</record>
<record id="hr_payroll_rules_mi_unemp" model="hr.salary.rule">
<field name="sequence" eval="443"/>
<field name="category_id" ref="hr_payroll_mi_unemp"/>
<field name="name">ER: US-MI Unemployment</field>
<field name="code">ER_US_MI_UNEMP</field>
<field name="condition_select">python</field>
<field name="condition_python">result = (contract.futa_type != contract.FUTA_TYPE_BASIC)</field>
<field name="amount_select">code</field>
<field name="amount_python_compute">
rate = payslip.dict.get_rate('US_MI_UNEMP')
result_rate = -rate.rate
result = categories.WAGE_US_MI_UNEMP
# result_rate of 0 implies 100% due to bug
if result_rate == 0.0:
result = 0.0
</field>
<field name="register_id" ref="contrib_register_mi_uia_unemp"/>
<field name="appears_on_payslip" eval="False"/>
</record>
<record id="hr_payroll_rules_mi_inc_withhold" model="hr.salary.rule">
<field name="sequence" eval="155"/>
<field name="category_id" ref="hr_payroll_mi_income_withhold"/>
<field name="name">EE: US-MI Income Tax Withholding</field>
<field name="code">EE_US_MI_INC_WITHHOLD</field>
<field name="condition_select">python</field>
<field name="condition_python">result = not contract.mi_w4_tax_exempt</field>
<field name="amount_select">code</field>
<field name="amount_python_compute">
wages = categories.GROSS
allowances = contract.mi_w4_exemptions
schedule_pay = contract.schedule_pay
annual_exemption_amount = 4400.00 * allowances
allowance_amount = 0.0
pay_period = 0.0
pay_periods = {
'weekly': 52.0,
'bi-weekly': 26.0,
'semi-monthly': 24.0,
'monthly': 12.0
}
if schedule_pay in pay_periods:
pay_period = pay_periods[schedule_pay]
else:
raise Exception('Invalid schedule_pay="' + schedule_pay + '" for MI Income Withholding calculation')
allowance_amount = (annual_exemption_amount / pay_period)
withholding = round((wages - allowance_amount) * 0.0425) + contract.mi_w4_additional_wh
result = - withholding
</field>
<field name="register_id" ref="contrib_register_mi_dot_withhold"/>
</record>
</odoo>

View File

@@ -0,0 +1 @@
from . import hr_payroll

View File

@@ -0,0 +1,10 @@
from odoo import models, fields, api
class USMIHrContract(models.Model):
_inherit = 'hr.contract'
mi_w4_exemptions = fields.Integer(string='Michigan W-4 Allowances', default=0)
mi_w4_additional_wh = fields.Float(string="Additional Withholding", default=0.0)
mi_w4_tax_exempt = fields.Boolean(string="Tax Exempt")

View File

@@ -0,0 +1 @@
from . import test_us_mi_payslip

View File

@@ -0,0 +1,294 @@
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 TestUsMIPayslip(TestUsPayslip):
# Taxes and Rates
MI_UNEMP_MAX_WAGE = 9000.0
MI_UNEMP = - 6.0 / 100.0
MI_INC_TAX = - 4.25 / 100.0
ANNUAL_EXEMPTION_AMOUNT = 4400.00
PAY_PERIOD_DIVISOR = {
'weekly': 52.0,
'bi-weekly': 26.0,
'semi-monthly': 24.0,
'monthly': 12.0
}
def test_2019_taxes_weekly(self):
salary = 5000.0
schedule_pay = 'weekly'
exemptions = 1
allowance_amount = self.ANNUAL_EXEMPTION_AMOUNT / self.PAY_PERIOD_DIVISOR[schedule_pay]
wh = -round((salary - (allowance_amount * exemptions)) * -self.MI_INC_TAX)
employee = self._createEmployee()
contract = self._createContract(employee,
salary,
struct_id=self.ref('l10n_us_mi_hr_payroll.hr_payroll_salary_structure_us_mi_employee'),
schedule_pay=schedule_pay)
contract.mi_w4_exemptions = exemptions
self.assertEqual(contract.schedule_pay, 'weekly')
self._log('2019 Michigan 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_MI_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MI_UNEMP'], cats['WAGE_US_MI_UNEMP'] * self.MI_UNEMP)
self.assertPayrollEqual(cats['EE_US_MI_INC_WITHHOLD'], wh)
process_payslip(payslip)
# Make a new payslip, this one will have maximums
remaining_MI_UNEMP_wages = self.MI_UNEMP_MAX_WAGE - salary if (self.MI_UNEMP_MAX_WAGE - 2*salary < salary) \
else salary
self._log('2019 Michigan 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_MI_UNEMP'], remaining_MI_UNEMP_wages)
self.assertPayrollEqual(cats['ER_US_MI_UNEMP'], remaining_MI_UNEMP_wages * self.MI_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_mi_hr_payroll.hr_payroll_salary_structure_us_mi_employee'),
schedule_pay=schedule_pay)
self._log('2019 Michigan 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_MI_UNEMP'], max(self.MI_UNEMP_MAX_WAGE - external_wages, 0.0))
self.assertPayrollEqual(cats['ER_US_MI_UNEMP'], cats['WAGE_US_MI_UNEMP'] * self.MI_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_mi_hr_payroll.hr_payroll_salary_structure_us_mi_employee'),
futa_type=USHrContract.FUTA_TYPE_BASIC, schedule_pay=schedule_pay)
self._log('2019 Michigan 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_MI_UNEMP', 0.0), 0.0)
self.assertPayrollEqual(cats.get('ER_US_MI_UNEMP', 0.0), cats.get('WAGE_US_MI_UNEMP', 0.0) * self.MI_UNEMP)
def test_2019_taxes_biweekly(self):
salary = 5000.0
schedule_pay = 'bi-weekly'
allowance_amount = 0.0
allowance_amount = self.ANNUAL_EXEMPTION_AMOUNT / self.PAY_PERIOD_DIVISOR[schedule_pay]
allowances = 2
wh = -round((salary - (allowance_amount * allowances)) * -self.MI_INC_TAX)
employee = self._createEmployee()
contract = self._createContract(employee, salary, struct_id=self.ref(
'l10n_us_mi_hr_payroll.hr_payroll_salary_structure_us_mi_employee'),
schedule_pay=schedule_pay)
contract.mi_w4_exemptions = allowances
self.assertEqual(contract.schedule_pay, 'bi-weekly')
self._log('2019 Michigan 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_MI_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MI_UNEMP'], cats['WAGE_US_MI_UNEMP'] * self.MI_UNEMP)
self.assertPayrollEqual(cats['EE_US_MI_INC_WITHHOLD'], wh)
process_payslip(payslip)
# Make a new payslip, this one will have maximums
remaining_MI_UNEMP_wages = self.MI_UNEMP_MAX_WAGE - salary if (self.MI_UNEMP_MAX_WAGE - 2*salary < salary) \
else salary
self._log('2019 Michigan 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_MI_UNEMP'], remaining_MI_UNEMP_wages)
self.assertPayrollEqual(cats['ER_US_MI_UNEMP'], remaining_MI_UNEMP_wages * self.MI_UNEMP)
def test_2019_taxes_semimonthly(self):
salary = 5000.0
schedule_pay = 'semi-monthly'
allowance_amount = self.ANNUAL_EXEMPTION_AMOUNT / self.PAY_PERIOD_DIVISOR[schedule_pay]
allowances = 1
wh = -round((salary - (allowance_amount * allowances)) * -self.MI_INC_TAX)
employee = self._createEmployee()
contract = self._createContract(employee, salary, struct_id=self.ref(
'l10n_us_mi_hr_payroll.hr_payroll_salary_structure_us_mi_employee'),
schedule_pay=schedule_pay)
contract.mi_w4_exemptions = allowances
self.assertEqual(contract.schedule_pay, 'semi-monthly')
self._log('2019 Michigan tax first payslip semi-monthly:')
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MI_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MI_UNEMP'], cats['WAGE_US_MI_UNEMP'] * self.MI_UNEMP)
self.assertPayrollEqual(cats['EE_US_MI_INC_WITHHOLD'], wh)
process_payslip(payslip)
# Make a new payslip, this one will have maximums
remaining_MI_UNEMP_wages = self.MI_UNEMP_MAX_WAGE - salary if (self.MI_UNEMP_MAX_WAGE - 2 * salary < salary) \
else salary
self._log('2019 Michigan tax second payslip semi-monthly:')
payslip = self._createPayslip(employee, '2019-02-01', '2019-02-28')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MI_UNEMP'], remaining_MI_UNEMP_wages)
self.assertPayrollEqual(cats['ER_US_MI_UNEMP'], remaining_MI_UNEMP_wages * self.MI_UNEMP)
def test_2019_taxes_monthly(self):
salary = 5000.0
schedule_pay = 'monthly'
allowance_amount = self.ANNUAL_EXEMPTION_AMOUNT / self.PAY_PERIOD_DIVISOR[schedule_pay]
allowances = 1
wh = -round((salary - (allowance_amount * allowances)) * -self.MI_INC_TAX)
employee = self._createEmployee()
contract = self._createContract(employee, salary, struct_id=self.ref(
'l10n_us_mi_hr_payroll.hr_payroll_salary_structure_us_mi_employee'),
schedule_pay=schedule_pay)
contract.mi_w4_exemptions = allowances
self.assertEqual(contract.schedule_pay, 'monthly')
self._log('2019 Michigan tax first payslip monthly:')
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MI_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MI_UNEMP'], cats['WAGE_US_MI_UNEMP'] * self.MI_UNEMP)
self.assertPayrollEqual(cats['EE_US_MI_INC_WITHHOLD'], wh)
process_payslip(payslip)
# Make a new payslip, this one will have maximums
remaining_MI_UNEMP_wages = self.MI_UNEMP_MAX_WAGE - salary if (
self.MI_UNEMP_MAX_WAGE - (2 * salary) < salary) \
else salary
self._log('2019 Michigan tax second payslip monthly:')
payslip = self._createPayslip(employee, '2019-02-01', '2019-02-28')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MI_UNEMP'], remaining_MI_UNEMP_wages)
self.assertPayrollEqual(cats['ER_US_MI_UNEMP'], remaining_MI_UNEMP_wages * self.MI_UNEMP)
def test_tax_exempt(self):
salary = 5000.0
wh = 0
schedule_pay = 'weekly'
exemptions = 1
employee = self._createEmployee()
contract = self._createContract(employee, salary, struct_id=self.ref(
'l10n_us_mi_hr_payroll.hr_payroll_salary_structure_us_mi_employee'),
schedule_pay=schedule_pay)
contract.mi_w4_exemptions = exemptions
contract.mi_w4_tax_exempt = True
self.assertEqual(contract.schedule_pay, 'weekly')
self._log('2019 Michigan tax first payslip exempt:')
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MI_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MI_UNEMP'], cats['WAGE_US_MI_UNEMP'] * self.MI_UNEMP)
self.assertPayrollEqual(cats.get('EE_US_MI_INC_WITHHOLD', 0.0), 0.0)
process_payslip(payslip)
# Make a new payslip, this one will have maximums
remaining_MI_UNEMP_wages = self.MI_UNEMP_MAX_WAGE - salary if (
self.MI_UNEMP_MAX_WAGE - 2 * salary < salary) \
else salary
self._log('2019 Michigan tax second payslip exempt:')
payslip = self._createPayslip(employee, '2019-02-01', '2019-02-28')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MI_UNEMP'], remaining_MI_UNEMP_wages)
self.assertPayrollEqual(cats['ER_US_MI_UNEMP'], remaining_MI_UNEMP_wages * self.MI_UNEMP)
def test_additional_withholding(self):
salary = 5000.0
schedule_pay = 'weekly'
allowance_amount = 0.0
allowance_amount = self.ANNUAL_EXEMPTION_AMOUNT / self.PAY_PERIOD_DIVISOR[schedule_pay]
additional_wh = 40.0
allowances = 1
wh = -round(((salary - (allowance_amount * allowances)) * -self.MI_INC_TAX) + additional_wh)
employee = self._createEmployee()
contract = self._createContract(employee,
salary,
struct_id=self.ref('l10n_us_mi_hr_payroll.hr_payroll_salary_structure_us_mi_employee'),
schedule_pay=schedule_pay)
contract.mi_w4_additional_wh = additional_wh
contract.mi_w4_exemptions = allowances
self.assertEqual(contract.schedule_pay, 'weekly')
self._log('2019 Michigan tax first payslip with additional withholding:')
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MI_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MI_UNEMP'], cats['WAGE_US_MI_UNEMP'] * self.MI_UNEMP)
self.assertPayrollEqual(cats['EE_US_MI_INC_WITHHOLD'], wh)
process_payslip(payslip)
# Make a new payslip, this one will have maximums
remaining_MI_UNEMP_wages = 4000.00
self._log('2019 Michigan tax second payslip with additional withholding:')
payslip = self._createPayslip(employee, '2019-02-01', '2019-02-28')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MI_UNEMP'], remaining_MI_UNEMP_wages)
self.assertPayrollEqual(cats['ER_US_MI_UNEMP'], remaining_MI_UNEMP_wages * self.MI_UNEMP)

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="hr_contract_form_l10n_us_mi_inherit" model="ir.ui.view">
<field name="name">hr.contract.form.inherit</field>
<field name="model">hr.contract</field>
<field name="priority">130</field>
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//group[@name='state_filing']" position="inside">
<group string="Michigan" name="mi">
<field name="mi_w4_exemptions" string="Exemptions"/>
<field name="mi_w4_additional_wh" string="Additional Withholding"/>
<field name="mi_w4_tax_exempt" string="Tax Exempt"/>
</group>
</xpath>
</data>
</field>
</record>
</data>
</odoo>