diff --git a/l10n_us_mt_hr_payroll/README.rst b/l10n_us_mt_hr_payroll/README.rst
new file mode 100644
index 00000000..d7719869
--- /dev/null
+++ b/l10n_us_mt_hr_payroll/README.rst
@@ -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 `_.
+
+=============
+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 `_.
+Copyright Hibou Corp. 2019
diff --git a/l10n_us_mt_hr_payroll/__init__.py b/l10n_us_mt_hr_payroll/__init__.py
new file mode 100755
index 00000000..0650744f
--- /dev/null
+++ b/l10n_us_mt_hr_payroll/__init__.py
@@ -0,0 +1 @@
+from . import models
diff --git a/l10n_us_mt_hr_payroll/__manifest__.py b/l10n_us_mt_hr_payroll/__manifest__.py
new file mode 100755
index 00000000..64883a44
--- /dev/null
+++ b/l10n_us_mt_hr_payroll/__manifest__.py
@@ -0,0 +1,28 @@
+{
+ 'name': 'USA - Montana - Payroll',
+ 'author': 'Hibou Corp. ',
+ '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
+}
diff --git a/l10n_us_mt_hr_payroll/data/base.xml b/l10n_us_mt_hr_payroll/data/base.xml
new file mode 100755
index 00000000..95d98f01
--- /dev/null
+++ b/l10n_us_mt_hr_payroll/data/base.xml
@@ -0,0 +1,44 @@
+
+
+
+
+ Montana Department of Labor & Industries
+ 1
+
+
+
+ Montana Department of Revenue
+ 1
+
+
+
+ Montana Unemployment
+ Montana Department of Labor & Industries
+
+
+
+ Montana Income Tax Withholding
+ Montana Department of Revenue - Income Tax Withholding
+
+
+
+
+
+
+ Wage: US-MT Unemployment
+ WAGE_US_MT_UNEMP
+
+
+
+ ER: US-MT Unemployment
+ ER_US_MT_UNEMP
+
+
+
+
+ EE: US-MT Income Withholding
+ EE_US_MT_INC_WITHHOLD
+
+
+
+
diff --git a/l10n_us_mt_hr_payroll/data/final.xml b/l10n_us_mt_hr_payroll/data/final.xml
new file mode 100755
index 00000000..043fb4d6
--- /dev/null
+++ b/l10n_us_mt_hr_payroll/data/final.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+ US_MT_EMP
+ USA Montana Employee
+
+
+
+
+
+
diff --git a/l10n_us_mt_hr_payroll/data/rates.xml b/l10n_us_mt_hr_payroll/data/rates.xml
new file mode 100644
index 00000000..d4819123
--- /dev/null
+++ b/l10n_us_mt_hr_payroll/data/rates.xml
@@ -0,0 +1,12 @@
+
+
+
+
+ US Montana Unemployment
+ US_MT_UNEMP
+ 1.18
+ 2019-01-01
+
+
+
+
\ No newline at end of file
diff --git a/l10n_us_mt_hr_payroll/data/rules.xml b/l10n_us_mt_hr_payroll/data/rules.xml
new file mode 100755
index 00000000..37f39c47
--- /dev/null
+++ b/l10n_us_mt_hr_payroll/data/rules.xml
@@ -0,0 +1,126 @@
+
+
+
+
+
+
+
+ Wage: US-MT Unemployment
+ WAGE_US_MT_UNEMP
+ python
+ result = (contract.futa_type != contract.FUTA_TYPE_BASIC)
+ code
+
+###
+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 <= 0.0:
+ result = 0
+elif remaining < categories.BASIC:
+ result = remaining
+else:
+ result = categories.BASIC
+
+
+
+
+
+
+ ER: US-MT Unemployment
+ ER_US_MT_UNEMP
+ python
+ result = (contract.futa_type != contract.FUTA_TYPE_BASIC)
+ code
+
+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
+
+
+
+
+
+
+
+
+ EE: US-MT Income Withholding
+ EE_US_MT_INC_WITHHOLD
+ python
+ result = not contract.mt_mw4_exempt
+ code
+
+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 <= 0.0:
+ result = 0.0
+ else:
+ for data in bracket:
+ if T < data[0]:
+ result = round(data[1] + ((data[2] / 100.0) * (T - data[3])))
+ break
+
+result += additional
+result = -result
+
+
+
+
+
diff --git a/l10n_us_mt_hr_payroll/models/__init__.py b/l10n_us_mt_hr_payroll/models/__init__.py
new file mode 100644
index 00000000..e99aa24a
--- /dev/null
+++ b/l10n_us_mt_hr_payroll/models/__init__.py
@@ -0,0 +1 @@
+from . import hr_payroll
diff --git a/l10n_us_mt_hr_payroll/models/hr_payroll.py b/l10n_us_mt_hr_payroll/models/hr_payroll.py
new file mode 100755
index 00000000..be1ce49e
--- /dev/null
+++ b/l10n_us_mt_hr_payroll/models/hr_payroll.py
@@ -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')
diff --git a/l10n_us_mt_hr_payroll/tests/__init__.py b/l10n_us_mt_hr_payroll/tests/__init__.py
new file mode 100755
index 00000000..52aa2a64
--- /dev/null
+++ b/l10n_us_mt_hr_payroll/tests/__init__.py
@@ -0,0 +1 @@
+from . import test_us_mt_payslip_2019
diff --git a/l10n_us_mt_hr_payroll/tests/test_us_mt_payslip_2019.py b/l10n_us_mt_hr_payroll/tests/test_us_mt_payslip_2019.py
new file mode 100755
index 00000000..c17b5364
--- /dev/null
+++ b/l10n_us_mt_hr_payroll/tests/test_us_mt_payslip_2019.py
@@ -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)
diff --git a/l10n_us_mt_hr_payroll/views/hr_payroll_views.xml b/l10n_us_mt_hr_payroll/views/hr_payroll_views.xml
new file mode 100755
index 00000000..99f8dbac
--- /dev/null
+++ b/l10n_us_mt_hr_payroll/views/hr_payroll_views.xml
@@ -0,0 +1,22 @@
+
+
+
+
+ hr.contract.form.inherit
+ hr.contract
+ 139
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+