Merge branch 'mig/12.0/l10n_us_mt_hr_payroll' into 12.0-test

This commit is contained in:
Jared Kipe
2019-05-15 09:44:21 -07:00
12 changed files with 422 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
**********************************
Hibou - US Payroll - Montana State
**********************************
Calculations and contribution registers for Montana State Payroll.
For more information and add-ons, visit `Hibou.io <https://hibou.io/>`_.
=============
Main Features
=============
* New Partners and Contribution Registers for:
* Montana Department of Revenue
* Montana Department of Labor & Industry
* Contract level Montana Exemptions and MW-4 fields
* Payroll Rate for Montana L&I Unemployment Rate
=======
License
=======
Please see `LICENSE <https://github.com/hibou-io/hibou-odoo-suite/blob/master/LICENSE>`_.
Copyright Hibou Corp. 2019

View File

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

View File

@@ -0,0 +1,28 @@
{
'name': 'USA - Montana - Payroll',
'author': 'Hibou Corp. <hello@hibou.io>',
'license': 'AGPL-3',
'category': 'Localization',
'depends': ['l10n_us_hr_payroll'],
'version': '12.0.2019.0.0',
'description': """
USA::Montana Payroll Rules.
===========================
* New Partners and Contribution Registers for:
* Montana Department of Revenue
* Montana Department of Labor & Industry
* Contract level Montana Exemptions and MW-4 fields
* Payroll Rate for Montana L&I 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,44 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- CONTRIBUTION REGISTERS -->
<record id="res_partner_mtdor_unemp" model="res.partner">
<field name="name">Montana Department of Labor &amp; Industries</field>
<field name="supplier">1</field>
<field eval="0" name="customer"/>
</record>
<record id="res_partner_mtdor_withhold" model="res.partner">
<field name="name">Montana Department of Revenue</field>
<field name="supplier">1</field>
<field eval="0" name="customer"/>
</record>
<record id="contrib_register_mtdor_unemp" model="hr.contribution.register">
<field name="name">Montana Unemployment</field>
<field name="note">Montana Department of Labor &amp; Industries</field>
<field name="partner_id" ref="res_partner_mtdor_unemp"/>
</record>
<record id="contrib_register_mtdor_withhold" model="hr.contribution.register">
<field name="name">Montana Income Tax Withholding</field>
<field name="note">Montana Department of Revenue - Income Tax Withholding</field>
<field name="partner_id" ref="res_partner_mtdor_withhold"/>
</record>
<!-- HR SALARY RULE CATEGORIES-->
<record id="hr_payroll_mt_unemp_wages" model="hr.salary.rule.category">
<field name="name">Wage: US-MT Unemployment</field>
<field name="code">WAGE_US_MT_UNEMP</field>
</record>
<record id="hr_payroll_mt_unemp" model="hr.salary.rule.category">
<field name="name">ER: US-MT Unemployment</field>
<field name="code">ER_US_MT_UNEMP</field>
<field name="parent_id" ref="hr_payroll.COMP"/>
</record>
<record id="hr_payroll_mt_income_withhold" model="hr.salary.rule.category">
<field name="name">EE: US-MT Income Withholding</field>
<field name="code">EE_US_MT_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_mt_employee" model="hr.payroll.structure">
<field name="code">US_MT_EMP</field>
<field name="name">USA Montana Employee</field>
<field eval="[(6, 0, [
ref('hr_payroll_rules_mt_unemp_wages'),
ref('hr_payroll_rules_mt_unemp'),
ref('hr_payroll_rules_mt_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,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data noupdate="1">
<record id="hr_payroll_rates_mt_unemp_2019" model="hr.payroll.rate">
<field name="name">US Montana Unemployment</field>
<field name="code">US_MT_UNEMP</field>
<field name="rate">1.18</field>
<field name="date_from">2019-01-01</field>
<field name="wage_limit_year" eval="33000.0"/>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- HR SALARY RULES-->
<record id="hr_payroll_rules_mt_unemp_wages" model="hr.salary.rule">
<field name="sequence" eval="423"/>
<field name="category_id" ref="hr_payroll_mt_unemp_wages"/>
<field name="name">Wage: US-MT Unemployment</field>
<field name="code">WAGE_US_MT_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">
###
year = payslip.dict.date_to.year
rate = payslip.dict.get_rate('US_MT_UNEMP')
ytd = payslip.sum('WAGE_US_MT_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_mt_unemp" model="hr.salary.rule">
<field name="sequence" eval="443"/>
<field name="category_id" ref="hr_payroll_mt_unemp"/>
<field name="name">ER: US-MT Unemployment</field>
<field name="code">ER_US_MT_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_MT_UNEMP')
result_rate = -rate.rate
result = categories.WAGE_US_MT_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_mtdor_unemp"/>
<field name="appears_on_payslip" eval="False"/>
</record>
<record id="hr_payroll_rules_mt_inc_withhold" model="hr.salary.rule">
<field name="sequence" eval="145"/>
<field name="category_id" ref="hr_payroll_mt_income_withhold"/>
<field name="name">EE: US-MT Income Withholding</field>
<field name="code">EE_US_MT_INC_WITHHOLD</field>
<field name="condition_select">python</field>
<field name="condition_python">result = not contract.mt_mw4_exempt</field>
<field name="amount_select">code</field>
<field name="amount_python_compute">
year = payslip.dict.date_to.year
G = categories.GROSS
N = contract.mt_mw4_exemptions
additional = contract.mt_mw4_additional_withholding
schedule_pay = contract.schedule_pay
result = 0.00
float_max = float('inf')
if year == 2019 or True:
if schedule_pay == 'weekly':
bracket = [
(135.0, 0.0, 1.80, 0.0),
(288.0, 2.0, 4.40, 135.0),
(2308.0, 9.0, 6.00, 288.0),
(float_max, 130.0, 6.60, 2308.0),
]
exemption_rate = 37.0
elif schedule_pay == 'bi-weekly':
bracket = [
(269.0, 0.0, 1.80, 0.0),
(577.0, 5.0, 4.40, 269.0),
(4615.0, 18.0, 6.00, 577.0),
(float_max, 261.0, 6.60, 4615.0),
]
exemption_rate = 73.0
elif schedule_pay == 'semi-monthly':
bracket = [
(292.0, 0.0, 1.80, 0.0),
(625.0, 5.0, 4.40, 292.0),
(5000.0, 20.0, 6.00, 625.0),
(float_max, 282.0, 6.60, 5000.0),
]
exemption_rate = 79.0
elif schedule_pay == 'monthly':
bracket = [
(583.0, 0.0, 1.80, 0.0),
(1250.0, 11.0, 4.40, 583.0),
(10000.0, 40.0, 6.00, 1250.0),
(float_max, 565.0, 6.60, 10000.0),
]
exemption_rate = 158.0
elif schedule_pay == 'annually':
bracket = [
(7000.0, 0.0, 1.80, 0.0),
(15000.0, 126.0, 4.40, 7000.0),
(120000.0, 478.0, 6.00, 15000.0),
(float_max, 6778.0, 6.60, 120000.0),
]
exemption_rate = 1900.0
else:
raise Exception('Invalid schedule_pay=' + schedule_pay + ' for MT Income Withholding')
T = G - (exemption_rate * N)
if T &lt;= 0.0:
result = 0.0
else:
for data in bracket:
if T &lt; data[0]:
result = round(data[1] + ((data[2] / 100.0) * (T - data[3])))
break
result += additional
result = -result
</field>
<field name="register_id" ref="contrib_register_mtdor_withhold"/>
</record>
</odoo>

View File

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

View File

@@ -0,0 +1,17 @@
from odoo import models, fields
class USMTHrContract(models.Model):
_inherit = 'hr.contract'
mt_mw4_exemptions = fields.Integer(string='Montana MW-4 Exemptions', default=0,
help='Box G')
mt_mw4_additional_withholding = fields.Float(string="Montana MW-4 Additional Withholding", default=0.0,
help='Box H')
mt_mw4_exempt = fields.Selection([
('', 'Not Exempt'),
('tribe', 'Registered Tribe'),
('reserve', 'Reserve or National Guard'),
('north_dakota', 'North Dakota'),
('montana_for_marriage', 'Montana for Marriage'),
], string='Exemption from Montana Withholding', default='', help='Section 2')

View File

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

View File

@@ -0,0 +1,129 @@
from odoo.addons.l10n_us_hr_payroll.tests.test_us_payslip import TestUsPayslip, process_payslip
class TestUsMtPayslip(TestUsPayslip):
# Calculations from https://app.mt.gov/myrevenue/Endpoint/DownloadPdf?yearId=705
MT_UNEMP = -1.18 / 100.0
def test_2019_taxes_one(self):
# Payroll Period Semi-Monthly example
salary = 550
mt_mw4_exemptions = 5
employee = self._createEmployee()
contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_mt_hr_payroll.hr_payroll_salary_structure_us_mt_employee'),
schedule_pay='semi-monthly')
contract.mt_mw4_exemptions = mt_mw4_exemptions
self._log('2019 Montana tax single first payslip:')
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MT_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MT_UNEMP'], cats['WAGE_US_MT_UNEMP'] * self.MT_UNEMP)
mt_taxable_income = salary - (79.0 * mt_mw4_exemptions)
mt_withhold = round(0 + (0.018 * (mt_taxable_income - 0)))
self.assertPayrollEqual(mt_taxable_income, 155.0)
self.assertPayrollEqual(mt_withhold, 3.0)
self.assertPayrollEqual(cats['EE_US_MT_INC_WITHHOLD'], -mt_withhold)
def test_2019_taxes_two(self):
# Payroll Period Bi-Weekly example
salary = 2950
mt_mw4_exemptions = 2
employee = self._createEmployee()
contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_mt_hr_payroll.hr_payroll_salary_structure_us_mt_employee'),
schedule_pay='bi-weekly')
contract.mt_mw4_exemptions = mt_mw4_exemptions
self._log('2019 Montana tax single first payslip:')
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MT_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MT_UNEMP'], cats['WAGE_US_MT_UNEMP'] * self.MT_UNEMP)
# Note!!
# The example calculation uses A = 16 but the actual table describes this as A = 18
mt_taxable_income = salary - (73.0 * mt_mw4_exemptions)
mt_withhold = round(18 + (0.06 * (mt_taxable_income - 577)))
self.assertPayrollEqual(mt_taxable_income, 2804.0)
self.assertPayrollEqual(mt_withhold, 152.0)
self.assertPayrollEqual(cats['EE_US_MT_INC_WITHHOLD'], -mt_withhold)
def test_2019_taxes_three(self):
# Payroll Period Weekly example
salary = 135
mt_mw4_exemptions = 1
employee = self._createEmployee()
contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_mt_hr_payroll.hr_payroll_salary_structure_us_mt_employee'),
schedule_pay='weekly')
contract.mt_mw4_exemptions = mt_mw4_exemptions
self._log('2019 Montana tax single first payslip:')
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_MT_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_MT_UNEMP'], cats['WAGE_US_MT_UNEMP'] * self.MT_UNEMP)
mt_taxable_income = salary - (37.0 * mt_mw4_exemptions)
mt_withhold = round(0 + (0.018 * (mt_taxable_income - 0)))
self.assertPayrollEqual(mt_taxable_income, 98.0)
self.assertPayrollEqual(mt_withhold, 2.0)
self.assertPayrollEqual(cats['EE_US_MT_INC_WITHHOLD'], -mt_withhold)
def test_2019_taxes_three_exempt(self):
# Payroll Period Weekly example
salary = 135
mt_mw4_exemptions = 1
employee = self._createEmployee()
contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_mt_hr_payroll.hr_payroll_salary_structure_us_mt_employee'),
schedule_pay='weekly')
contract.mt_mw4_exemptions = mt_mw4_exemptions
contract.mt_mw4_exempt = 'reserve'
self._log('2019 Montana tax single first payslip:')
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats.get('EE_US_MT_INC_WITHHOLD', 0.0), 0.0)
def test_2019_taxes_three_additional(self):
# Payroll Period Weekly example
salary = 135
mt_mw4_exemptions = 1
mt_mw4_additional_withholding = 20.0
employee = self._createEmployee()
contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_mt_hr_payroll.hr_payroll_salary_structure_us_mt_employee'),
schedule_pay='weekly')
contract.mt_mw4_exemptions = mt_mw4_exemptions
contract.mt_mw4_additional_withholding = mt_mw4_additional_withholding
self._log('2019 Montana tax single first payslip:')
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
payslip.compute_sheet()
cats = self._getCategories(payslip)
mt_taxable_income = salary - (37.0 * mt_mw4_exemptions)
mt_withhold = round(0 + (0.018 * (mt_taxable_income - 0)))
self.assertPayrollEqual(mt_taxable_income, 98.0)
self.assertPayrollEqual(mt_withhold, 2.0)
self.assertPayrollEqual(cats['EE_US_MT_INC_WITHHOLD'], -mt_withhold + -mt_mw4_additional_withholding)

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="hr_contract_form_l10n_us_mt_inherit" model="ir.ui.view">
<field name="name">hr.contract.form.inherit</field>
<field name="model">hr.contract</field>
<field name="priority">139</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="Montana" name="mt">
<field name="mt_mw4_exemptions" string="Exceptions"/>
<field name="mt_mw4_additional_withholding" string="Additional Withholding"/>
<field name="mt_mw4_exempt" string="Withholding Exempt Reason"/>
</group>
</xpath>
</data>
</field>
</record>
</data>
</odoo>