MIG l10n_us_wa_hr_payroll Migrate to 12.0 and Payroll 2019 standards

This commit is contained in:
Jared Kipe
2019-10-28 17:36:09 -07:00
parent bc1f62f523
commit 7b41b6c264
13 changed files with 204 additions and 151 deletions

View File

@@ -1 +1 @@
from . import hr_payroll
from . import models

View File

@@ -4,7 +4,7 @@
'license': 'AGPL-3',
'category': 'Localization',
'depends': ['l10n_us_hr_payroll'],
'version': '11.0.2018.0.0',
'version': '12.0.2019.0.0',
'description': """
USA::Washington Payroll Rules.
==============================
@@ -19,9 +19,10 @@ USA::Washington Payroll Rules.
'website': 'https://hibou.io/',
'data': [
'security/ir.model.access.csv',
'hr_payroll_view.xml',
'views/hr_payroll_views.xml',
'data/base.xml',
'data/rules_2018.xml',
'data/rates.xml',
'data/rules.xml',
'data/final.xml',
],
'installable': True

View File

@@ -26,63 +26,27 @@
<!-- HR SALARY RULE CATEGORIES-->
<record id="hr_payroll_wa_unemp_wages" model="hr.salary.rule.category">
<field name="name">Washington Unemployment - Wages</field>
<field name="code">WA_UNEMP_WAGES</field>
<field name="name">Wage: US-WA Unemployment</field>
<field name="code">WAGE_US_WA_UNEMP</field>
</record>
<record id="hr_payroll_wa_unemp" model="hr.salary.rule.category">
<field name="name">Washington Unemployment</field>
<field name="code">WA_UNEMP</field>
<field name="name">ER: US-WA Unemployment</field>
<field name="code">ER_US_WA_UNEMP</field>
<field name="parent_id" ref="hr_payroll.COMP"/>
</record>
<record id="hr_payroll_wa_lni" model="hr.salary.rule.category">
<field name="name">Washington LNI</field>
<field name="code">WA_LNI</field>
<field name="name">ER: US-WA LNI</field>
<field name="code">ER_US_WA_LNI</field>
<field name="parent_id" ref="hr_payroll.COMP"/>
</record>
<record id="hr_payroll_wa_lni_withhold" model="hr.salary.rule.category">
<field name="name">Washington LNI Withholding</field>
<field name="code">WA_LNI_WITHHOLD</field>
<field name="name">EE: US-WA LNI</field>
<field name="code">EE_US_WA_LNI</field>
<field name="parent_id" ref="hr_payroll.DED"/>
</record>
<!-- HR SALARY RULES -->
<record id="hr_payroll_rules_wa_lni_withhold" model="hr.salary.rule">
<field name="sequence" eval="150"/>
<field name="category_id" ref="hr_payroll_wa_lni_withhold"/>
<field name="name">Washington LNI Withholding</field>
<field name="code">WA_LNI_WITHHOLD</field>
<field name="condition_select">none</field>
<field name="amount_select">code</field>
<field name="amount_python_compute">
hours = worked_days.WORK100.number_of_hours
rate = contract.wa_lni.rate_emp_withhold
if rate:
result = -(hours * rate)
</field>
<field name="register_id" ref="contrib_register_wador_lni"/>
</record>
<record id="hr_payroll_rules_wa_lni" model="hr.salary.rule">
<field name="sequence" eval="155"/>
<field name="category_id" ref="hr_payroll_wa_lni"/>
<field name="name">Washington LNI</field>
<field name="code">WA_LNI</field>
<field name="appears_on_payslip" eval="False"/>
<field name="condition_select">none</field>
<field name="amount_select">code</field>
<field name="amount_python_compute">
hours = worked_days.WORK100.number_of_hours
rate = contract.wa_lni.rate
withholding = categories.WA_LNI_WITHHOLD
if rate:
result = -(hours * rate) - withholding
</field>
<field name="register_id" ref="contrib_register_wador_lni"/>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data noupdate="1">
<record id="hr_payroll_rates_wa_unemp_2018" model="hr.payroll.rate">
<field name="name">US Washington Unemployment</field>
<field name="code">US_WA_UNEMP</field>
<field name="rate">1.16</field>
<field name="date_from">2018-01-01</field>
<field name="wage_limit_year" eval="47300.0"/>
</record>
<record id="hr_payroll_rates_wa_unemp_2019" model="hr.payroll.rate">
<field name="name">US Washington Unemployment</field>
<field name="code">US_WA_UNEMP</field>
<field name="rate">1.03</field>
<field name="date_from">2019-01-01</field>
<field name="wage_limit_year" eval="49800.0"/>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- HR SALARY RULES-->
<record id="hr_payroll_rules_wa_unemp_wages_2018" model="hr.salary.rule">
<field name="sequence" eval="423"/>
<field name="category_id" ref="hr_payroll_wa_unemp_wages"/>
<field name="name">Wage: US-WA Unemployment</field>
<field name="code">WAGE_US_WA_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_WA_UNEMP')
ytd = payslip.sum('WAGE_US_WA_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_wa_unemp_2018" model="hr.salary.rule">
<field name="sequence" eval="443"/>
<field name="category_id" ref="hr_payroll_wa_unemp"/>
<field name="name">ER: US-WA Unemployment</field>
<field name="code">ER_US_WA_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_WA_UNEMP')
result_rate = -rate.rate
result = categories.WAGE_US_WA_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_wador_unemp"/>
<field name="appears_on_payslip" eval="False"/>
</record>
<record id="hr_payroll_rules_wa_lni_withhold" model="hr.salary.rule">
<field name="sequence" eval="150"/>
<field name="category_id" ref="hr_payroll_wa_lni_withhold"/>
<field name="name">EE: US-WA LNI</field>
<field name="code">EE_US_WA_LNI</field>
<field name="condition_select">none</field>
<field name="amount_select">code</field>
<field name="amount_python_compute">
hours = worked_days.WORK100.number_of_hours
rate = contract.wa_lni.rate_emp_withhold
if rate:
result = -(hours * rate)
</field>
<field name="register_id" ref="contrib_register_wador_lni"/>
</record>
<record id="hr_payroll_rules_wa_lni" model="hr.salary.rule">
<field name="sequence" eval="155"/>
<field name="category_id" ref="hr_payroll_wa_lni"/>
<field name="name">ER: US-WA LNI</field>
<field name="code">ER_US_WA_LNI</field>
<field name="appears_on_payslip" eval="False"/>
<field name="condition_select">none</field>
<field name="amount_select">code</field>
<field name="amount_python_compute">
hours = worked_days.WORK100.number_of_hours
rate = contract.wa_lni.rate
withholding = categories.EE_US_WA_LNI
if rate:
result = -(hours * rate) - withholding
</field>
<field name="register_id" ref="contrib_register_wador_lni"/>
</record>
</odoo>

View File

@@ -1,49 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- HR SALARY RULES-->
<record id="hr_payroll_rules_wa_unemp_wages_2018" model="hr.salary.rule">
<field name="sequence" eval="423"/>
<field name="category_id" ref="hr_payroll_wa_unemp_wages"/>
<field name="name">Washington Unemployment - Wages (2018)</field>
<field name="code">WA_UNEMP_WAGES_2018</field>
<field name="condition_select">python</field>
<field name="condition_python">result = (payslip.date_to[:4] == '2018')</field>
<field name="amount_select">code</field>
<field name="amount_python_compute">
###
ytd = payslip.sum('WA_UNEMP_WAGES_2018', '2018-01-01', '2019-01-01')
ytd += contract.external_wages
remaining = 47300.0 - 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_wa_unemp_2018" model="hr.salary.rule">
<field name="sequence" eval="443"/>
<field name="category_id" ref="hr_payroll_wa_unemp"/>
<field name="name">Washington Unemployment (2018)</field>
<field name="code">WA_UNEMP_2018</field>
<field name="condition_select">python</field>
<field name="condition_python">result = (payslip.date_to[:4] == '2018')</field>
<field name="amount_select">code</field>
<field name="amount_python_compute">
result_rate = -contract.wa_unemp_rate(2018)
result = categories.WA_UNEMP_WAGES
# 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_wador_unemp"/>
<field name="appears_on_payslip" eval="False"/>
</record>
</data>
</odoo>

View File

@@ -1,33 +0,0 @@
from odoo import models, fields, api
class USWAHrContract(models.Model):
_inherit = 'hr.contract'
wa_lni = fields.Many2one('hr.contract.lni.wa', string='WA State LNI')
@api.multi
def wa_unemp_rate(self, year):
self.ensure_one()
if self.futa_type == self.FUTA_TYPE_BASIC:
return 0.0
if hasattr(self.employee_id.company_id, 'wa_unemp_rate_' + str(year)):
return self.employee_id.company_id['wa_unemp_rate_' + str(year)]
raise NotImplemented('Year (' + str(year) + ') Not implemented for US Washington.')
class WACompany(models.Model):
_inherit = 'res.company'
# No Defaults, need to sign up with the Employment Security Department
wa_unemp_rate_2018 = fields.Float(string="Washington Unemployment Rate 2018", default=0.0)
class WALNI(models.Model):
_name = 'hr.contract.lni.wa'
name = fields.Char(string='Name')
rate = fields.Float(string='Rate (per hour worked)', digits=(7, 6))
rate_emp_withhold = fields.Float(string='Employee Payroll Deduction Rate (per hour worked)', digits=(7, 6))

View File

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

View File

@@ -0,0 +1,15 @@
from odoo import models, fields, api
class USWAHrContract(models.Model):
_inherit = 'hr.contract'
wa_lni = fields.Many2one('hr.contract.lni.wa', string='WA State LNI')
class WALNI(models.Model):
_name = 'hr.contract.lni.wa'
name = fields.Char(string='Name')
rate = fields.Float(string='Rate (per hour worked)', digits=(7, 6))
rate_emp_withhold = fields.Float(string='Employee Payroll Deduction Rate (per hour worked)', digits=(7, 6))

View File

@@ -1 +1,2 @@
from . import test_us_wa_payslip_2018
from . import test_us_wa_payslip_2019

View File

@@ -6,6 +6,7 @@ class TestUsWAPayslip(TestUsPayslip):
# Taxes and Rates
###
WA_UNEMP_MAX_WAGE = 47300.0
WA_UNEMP_RATE = 1.16
def setUp(self):
super(TestUsWAPayslip, self).setUp()
@@ -19,14 +20,13 @@ class TestUsWAPayslip(TestUsPayslip):
salary = 25000.0
employee = self._createEmployee()
employee.company_id.wa_unemp_rate_2018 = 1.16
contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_wa_hr_payroll.hr_payroll_salary_structure_us_wa_employee'))
self._log(str(contract.resource_calendar_id) + ' ' + contract.resource_calendar_id.name)
contract.wa_lni = self.lni
# tax rates
wa_unemp = contract.wa_unemp_rate(2018) / -100.0
wa_unemp = self.WA_UNEMP_RATE / -100.0
self._log('2018 Washington tax first payslip:')
payslip = self._createPayslip(employee, '2018-01-01', '2018-01-31')
@@ -37,10 +37,10 @@ class TestUsWAPayslip(TestUsPayslip):
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WA_UNEMP_WAGES'], salary)
self.assertPayrollEqual(cats['WA_UNEMP'], cats['WA_UNEMP_WAGES'] * wa_unemp)
self.assertPayrollEqual(cats['WA_LNI_WITHHOLD'], -(self.lni.rate_emp_withhold * hours_in_period))
self.assertPayrollEqual(cats['WA_LNI'], -(self.lni.rate * hours_in_period) - cats['WA_LNI_WITHHOLD'])
self.assertPayrollEqual(cats['WAGE_US_WA_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_WA_UNEMP'], cats['WAGE_US_WA_UNEMP'] * wa_unemp)
self.assertPayrollEqual(cats['EE_US_WA_LNI'], -(self.lni.rate_emp_withhold * hours_in_period))
self.assertPayrollEqual(cats['ER_US_WA_LNI'], -(self.lni.rate * hours_in_period) - cats['EE_US_WA_LNI'])
process_payslip(payslip)
@@ -56,5 +56,5 @@ class TestUsWAPayslip(TestUsPayslip):
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WA_UNEMP_WAGES'], remaining_wa_unemp_wages)
self.assertPayrollEqual(cats['WA_UNEMP'], remaining_wa_unemp_wages * wa_unemp)
self.assertPayrollEqual(cats['WAGE_US_WA_UNEMP'], remaining_wa_unemp_wages)
self.assertPayrollEqual(cats['ER_US_WA_UNEMP'], remaining_wa_unemp_wages * wa_unemp)

View File

@@ -0,0 +1,60 @@
from odoo.addons.l10n_us_hr_payroll.tests.test_us_payslip import TestUsPayslip, process_payslip
class TestUsWAPayslip(TestUsPayslip):
###
# Taxes and Rates
###
WA_UNEMP_MAX_WAGE = 49800.0
WA_UNEMP_RATE = 1.03
def setUp(self):
super(TestUsWAPayslip, self).setUp()
self.lni = self.env['hr.contract.lni.wa'].create({
'name': '5302 Computer Consulting',
'rate': 0.1261,
'rate_emp_withhold': 0.05575,
})
def test_2019_taxes(self):
salary = 25000.0
employee = self._createEmployee()
contract = self._createContract(employee, salary, struct_id=self.ref('l10n_us_wa_hr_payroll.hr_payroll_salary_structure_us_wa_employee'))
self._log(str(contract.resource_calendar_id) + ' ' + contract.resource_calendar_id.name)
contract.wa_lni = self.lni
# tax rates
wa_unemp = self.WA_UNEMP_RATE / -100.0
self._log('2019 Washington tax first payslip:')
payslip = self._createPayslip(employee, '2019-01-01', '2019-01-31')
payslip.onchange_contract()
hours_in_period = payslip.worked_days_line_ids.filtered(lambda l: l.code == 'WORK100').number_of_hours
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_WA_UNEMP'], salary)
self.assertPayrollEqual(cats['ER_US_WA_UNEMP'], cats['WAGE_US_WA_UNEMP'] * wa_unemp)
self.assertPayrollEqual(cats['EE_US_WA_LNI'], -(self.lni.rate_emp_withhold * hours_in_period))
self.assertPayrollEqual(cats['ER_US_WA_LNI'], -(self.lni.rate * hours_in_period) - cats['EE_US_WA_LNI'])
process_payslip(payslip)
# Make a new payslip, this one will have maximums
remaining_wa_unemp_wages = self.WA_UNEMP_MAX_WAGE - salary if (self.WA_UNEMP_MAX_WAGE - 2*salary < salary) \
else salary
self._log('2019 Washington tax second payslip:')
payslip = self._createPayslip(employee, '2019-02-01', '2019-02-28')
payslip.onchange_contract()
payslip.compute_sheet()
cats = self._getCategories(payslip)
self.assertPayrollEqual(cats['WAGE_US_WA_UNEMP'], remaining_wa_unemp_wages)
self.assertPayrollEqual(cats['ER_US_WA_UNEMP'], remaining_wa_unemp_wages * wa_unemp)

View File

@@ -1,19 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="us_wa_view_company_form" model="ir.ui.view">
<field name="name">res.company.form</field>
<field name="model">res.company</field>
<field name="priority">64</field>
<field name="inherit_id" ref="base.view_company_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='currency_id']" position="after">
<field name="wa_unemp_rate_2018"/>
</xpath>
</data>
</field>
</record>
<record id="hr_contract_form_l10n_us_wa_inherit" model="ir.ui.view">
<field name="name">hr.contract.form.inherit</field>
<field name="model">hr.contract</field>