NEW l10n_us_mn_hr_payroll for 11.0

This commit is contained in:
David Frick
2019-07-11 14:07:25 -04:00
parent 097c42fc6b
commit 3ee1d7fdda
11 changed files with 452 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,28 @@
{
'name': 'USA - Minnesota - 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 - Minnesota Payroll Rules
=============================
* Contribution register and partner for Minnesota Department of Revenue (MDOR) - Income Tax Withholding
* Contribution register and partner for Minnesota Unemployment Insurance (MUI) - Unemployment Taxes
* Contract level Minnesota Exemptions
* Company level Minnesota 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,49 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- PARTNERS -->
<record id="res_partner_mn_ui_unemp" model="res.partner">
<field name="name">Minnesota Unemployment Insurance (MUI) - Unemployment Tax</field>
<field name="supplier">1</field>
<field eval="0" name="customer"/>
</record>
<record id="res_partner_mn_dor_withhold" model="res.partner">
<field name="name">Minnesota Department of Revenue (MDOR) - Income Tax Withholding</field>
<field name="supplier">1</field>
<field eval="0" name="customer"/>
</record>
<!-- CONTRIBUTION REGISTERS -->
<record id="contrib_register_mn_ui_unemp" model="hr.contribution.register">
<field name="name">Minnesota Unemployment</field>
<field name="note">Minnesota Unemployment Insurance (MUI) - Unemployment</field>
<field name="partner_id" ref="res_partner_mn_ui_unemp"/>
</record>
<record id="contrib_register_mn_dor_withhold" model="hr.contribution.register">
<field name="name">Minnesota Income Tax Withholding</field>
<field name="note">Minnesota Department of Revenue (MDOR) - Income Tax Withholding</field>
<field name="partner_id" ref="res_partner_mn_dor_withhold"/>
</record>
<!-- HR SALARY RULE CATEGORIES-->
<record id="hr_payroll_mn_unemp_wages" model="hr.salary.rule.category">
<field name="name">Wage: US-MN Unemployment</field>
<field name="code">WAGE_US_MN_UNEMP</field>
</record>
<record id="hr_payroll_mn_unemp" model="hr.salary.rule.category">
<field name="name">ER: US-MN Unemployment</field>
<field name="code">ER_US_MN_UNEMP</field>
<field name="parent_id" ref="hr_payroll.COMP"/>
</record>
<record id="hr_payroll_mn_income_withhold" model="hr.salary.rule.category">
<field name="name">EE: US-MN Income Tax Withholding</field>
<field name="code">EE_US_MN_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_mn_employee" model="hr.payroll.structure">
<field name="code">US_MN_EMP</field>
<field name="name">USA Minnesota Employee</field>
<field eval="[(6, 0, [
ref('hr_payroll_rules_mn_unemp_wages'),
ref('hr_payroll_rules_mn_unemp'),
ref('hr_payroll_rules_mn_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,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- THIS IS INDUSTRY SPECIFIC IN MINNESOTA -->
<record id="hr_payroll_rates_mn_unemp" model="hr.payroll.rate">
<field name="name">US MN Unemployment</field>
<field name="code">US_MN_UNEMP</field>
<field name="rate">1.11</field>
<field name="date_from">2019-01-01</field>
<field name="wage_limit_year" eval="34000.00"/>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- HR SALARY RULES-->
<record id="hr_payroll_rules_mn_unemp_wages" model="hr.salary.rule">
<field name="sequence" eval="423"/>
<field name="category_id" ref="hr_payroll_mn_unemp_wages"/>
<field name="name">Wage: US-MN Unemployment</field>
<field name="code">WAGE_US_MN_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_MN_UNEMP')
year = int(payslip.dict.date_to[:4])
ytd = payslip.sum('WAGE_US_MN_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_mn_unemp" model="hr.salary.rule">
<field name="sequence" eval="443"/>
<field name="category_id" ref="hr_payroll_mn_unemp"/>
<field name="name">ER: US-MN Unemployment</field>
<field name="code">ER_US_MN_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_MN_UNEMP')
result_rate = -rate.rate
result = categories.WAGE_US_MN_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_mn_ui_unemp"/>
<field name="appears_on_payslip" eval="False"/>
</record>
<record id="hr_payroll_rules_mn_inc_withhold" model="hr.salary.rule">
<field name="sequence" eval="155"/>
<field name="category_id" ref="hr_payroll_mn_income_withhold"/>
<field name="name">EE: US-MN Income Tax Withholding</field>
<field name="code">EE_US_MN_INC_WITHHOLD</field>
<field name="condition_select">python</field>
<field name="condition_python">result = not contract.mn_w4mn_tax_exempt</field>
<field name="amount_select">code</field>
<field name="amount_python_compute">
# Step 1 - Determine Employee's Total Wages for one payroll period.
wages = categories.GROSS
allowances = contract.mn_w4mn_allowances
schedule_pay = contract.schedule_pay
# Step 2 - Multiply the wages from step by number of payroll periods per year. This gives annual wage.
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 AR Income Withholding calculation')
annual_wages = wages * pay_period
# Step 3 - Multiple the number of employee's withholding allowances by $4,250
allowance_amount = 4250.00 * allowances
# Step 4 - Subtract the result in step 3 from the result in step 2.
taxable_wages = annual_wages - allowance_amount
# Step 5 - Use the result in step 4 (taxable wages) and the tax chart to calculate step 5 amount.
mn_w4_filing_status = contract.mn_w4mn_filing_status
tax_table = []
if mn_w4_filing_status == 'single':
tax_table = [
(28920, 2400, 5.35, 0.00),
(89510, 28920, 7.05, 1418.82),
(166290, 89510, 7.85, 5690.42),
(float('inf'), 166290, 9.85, 11717.65)
]
elif mn_w4_filing_status == 'married':
tax_table = [
(47820, 9050, 5.35, 0.00),
(163070, 47820, 7.05, 2074.20),
(282200, 163070, 7.85, 10199.33),
(float('inf'), 282200, 9.85, 19551.04)
]
else:
raise Exception('Invalid w4_filing_status="' + mn_w4_filing_status + '" for MN Income Withholding calculation')
last = 0.0
result = 0.0
for row in tax_table:
cap, subtract_amt, rate, flat_fee = row
if cap > taxable_wages:
taxed_amount = taxable_wages - subtract_amt
result = ((rate / 100.00) * taxed_amount) + flat_fee
break
# Make the result per pay period once more.
result = result / pay_period
# Round Result - Make sign negative as well - Add additional withholding here as well
result = -round(result) - contract.mn_w4mn_additional_wh
</field>
<field name="register_id" ref="contrib_register_mn_dor_withhold"/>
</record>
</odoo>

View File

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

View File

@@ -0,0 +1,14 @@
from odoo import models, fields, api
class USMNHrContract(models.Model):
_inherit = 'hr.contract'
mn_w4mn_allowances = fields.Integer(string="MN Allowances")
mn_w4mn_additional_wh = fields.Float(string="MN Additional Withholding")
mn_w4mn_tax_exempt = fields.Boolean(string="MN Tax Exempt")
mn_w4mn_filing_status = fields.Selection([
# ('exempt', 'Exempt'),
('single', 'Single'),
('married', 'Married'),
], string='MN Filing Status', default='single')

View File

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

View File

@@ -0,0 +1,182 @@
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 TestUsMNPayslip(TestUsPayslip):
# TAXES AND RATES
MN_UNEMP_MAX_WAGE = 34000.00
MN_UNEMP = -1.11 / 100.0
def test_taxes_weekly(self):
salary = 30000.00
schedule_pay = 'weekly'
allowances = 1
# Hand Calculated Amount to Test
# Step 1 -> 30000.00 for wages per period Step 2 -> 52.0 for weekly -> 30000 * 52 -> 1560000
# Step 3 -> allowances * 4250.0 -> 4250.00 in this case.
# Step 4 -> Step 2 - Step 3 -> 1560000 - 4250.00 -> 1555750
# Step 5 -> using chart -> we have last row -> ((1555750 - 166290) * (9.85 / 100)) + 11717.65 -> 148579.46
# Step 6 -> Convert back to pay period amount and round - > 2857.297 - > 2857.0
# wh = 2857.0
wh = -2857.0
employee = self._createEmployee()
contract = self._createContract(employee,
salary,
struct_id=self.ref('l10n_us_mn_hr_payroll.hr_payroll_salary_structure_us_mn_employee'),
schedule_pay=schedule_pay)
contract.mn_w4mn_allowances = allowances
self.assertEqual(contract.schedule_pay, 'weekly')
self._log('2019 Minnesota 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_MN_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MN_UNEMP'], cats['WAGE_US_MN_UNEMP'] * self.MN_UNEMP)
self.assertPayrollEqual(cats['EE_US_MN_INC_WITHHOLD'], wh)
process_payslip(payslip)
# Make a new payslip, this one will have maximums
remaining_MN_UNEMP_wages = self.MN_UNEMP_MAX_WAGE - salary if (self.MN_UNEMP_MAX_WAGE - 2*salary < salary) \
else salary
self._log('2019 Minnesota 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_MN_UNEMP'], remaining_MN_UNEMP_wages)
self.assertPayrollEqual(cats['ER_US_MN_UNEMP'], remaining_MN_UNEMP_wages * self.MN_UNEMP)
def test_taxes_married(self):
salary = 5000.00
schedule_pay = 'weekly'
allowances = 1
filing_status = 'married'
# Hand Calculated Amount to Test
# Step 1 -> 5000.0 for wages per period Step 2 -> 52.0 for weekly -> 5000 * 52 -> 260,000
# Step 3 -> allowances * 4250.0 -> 4250.00 in this case.
# Step 4 -> Step 2 - Step 3 -> 260,000 - 4250.00 -> 255750.0
# For step five we used the married section
# Step 5 -> using chart -> we have 2nd last row -> ((255750 - 163070) * (7.85 / 100)) + 10199.33 ->
# Step 6 -> Convert back to pay period amount and round
# wh = 336.0
wh = -336.0
employee = self._createEmployee()
contract = self._createContract(employee,
salary,
struct_id=self.ref('l10n_us_mn_hr_payroll.hr_payroll_salary_structure_us_mn_employee'),
schedule_pay=schedule_pay)
contract.mn_w4mn_allowances = allowances
contract.mn_w4mn_filing_status = filing_status
self.assertEqual(contract.schedule_pay, 'weekly')
self.assertEqual(contract.mn_w4mn_filing_status, 'married')
self._log('2019 Minnesota tax first payslip married:')
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MN_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MN_UNEMP'], cats['WAGE_US_MN_UNEMP'] * self.MN_UNEMP)
self.assertPayrollEqual(cats['EE_US_MN_INC_WITHHOLD'], wh)
def test_taxes_semimonthly(self):
salary = 6500.00
schedule_pay = 'semi-monthly'
mn_w4mn_filing_status = 'single'
allowances = 1
# Hand Calculated Amount to Test
# Step 1 -> 6500.00 for wages per period Step 2 -> 24 for semi-monthly -> 6500.00 * 24 -> 156000.00
# Step 3 -> allowances * 4250.0 -> 4250.00 in this case.
# Step 4 -> Step 2 - Step 3 -> 156000.00 - 4250.00 -> 151750.0
# Step 5 -> using chart -> we have 2nd last row -> ((151750.0- 89510) * (7.85 / 100)) + 5690.42 -> 10576.26
# Step 6 -> Convert back to pay period amount and round
# wh = -441
wh = -441.00
employee = self._createEmployee()
contract = self._createContract(employee,
salary,
struct_id=self.ref('l10n_us_mn_hr_payroll.hr_payroll_salary_structure_us_mn_employee'),
schedule_pay=schedule_pay)
contract.mn_w4mn_allowances = allowances
contract.mn_w4mn_filing_status = mn_w4mn_filing_status
self.assertEqual(contract.schedule_pay, 'semi-monthly')
self._log('2019 Minnesota tax first payslip semimonthly:')
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MN_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MN_UNEMP'], cats['WAGE_US_MN_UNEMP'] * self.MN_UNEMP)
self.assertPayrollEqual(cats['EE_US_MN_INC_WITHHOLD'], wh)
def test_tax_exempt(self):
salary = 5500.00
wh = 0
schedule_pay = 'weekly'
allowances = 2
employee = self._createEmployee()
contract = self._createContract(employee,
salary, struct_id=self.ref('l10n_us_mn_hr_payroll.hr_payroll_salary_structure_us_mn_employee'),
schedule_pay=schedule_pay)
contract.mn_w4mn_allowances = allowances
contract.mn_w4mn_tax_exempt = True
self.assertEqual(contract.schedule_pay, 'weekly')
self._log('2019 Minnesota 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_MN_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MN_UNEMP'], cats['WAGE_US_MN_UNEMP'] * self.MN_UNEMP)
self.assertPayrollEqual(cats.get('EE_US_MN_INC_WITHHOLD', 0.0), wh)
def test_additional_withholding(self):
salary = 5500.0
schedule_pay = 'weekly'
additional_wh = 40.0
allowances = 2
# Hand Calculated Amount to Test
# Step 1 -> 5500 for wages per period Step 2 -> 52 for weekly -> 5500 * 52 -> 286000.00
# Step 3 -> allowances * 4250.0 -> 8500 in this case.
# Step 4 -> Step 2 - Step 3 -> 286000.00 - 8500 -> 277500
# Step 5 -> using chart -> we have last row -> ((277500- 166290) * (9.85 / 100)) + 11717.65 -> 22671.835
# Step 6 -> Convert back to pay period amount and round
# wh = -436.0
# Add additional_withholding
# wh = -436.0 - 40.0
wh = -436.0
employee = self._createEmployee()
contract = self._createContract(employee,
salary,
struct_id=self.ref('l10n_us_mn_hr_payroll.hr_payroll_salary_structure_us_mn_employee'),
schedule_pay=schedule_pay)
contract.mn_w4mn_allowances = allowances
contract.mn_w4mn_additional_wh = additional_wh
self.assertEqual(contract.schedule_pay, 'weekly')
self._log('2019 Minnesota tax first payslip additional withholding:')
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MN_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MN_UNEMP'], cats['WAGE_US_MN_UNEMP'] * self.MN_UNEMP)
self.assertPayrollEqual(cats['EE_US_MN_INC_WITHHOLD'], wh - additional_wh)

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="hr_contract_form_l10n_us_mc_inherit" model="ir.ui.view">
<field name="name">hr.contract.form.inherit</field>
<field name="model">hr.contract</field>
<field name="priority">128</field>
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='state_filing']" position="inside">
<group string="Minnesota" name="mn">
<field name="mn_w4mn_allowances" string="Allowances"/>
<field name="mn_w4mn_additional_wh" string="Additional Withholding"/>
<field name="mn_w4mn_tax_exempt" string="Tax Exempt"/>
<field name="mn_w4mn_filing_status" string="Filing Status"/>
</group>
</xpath>
</field>
</record>
</odoo>