<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <!-- Wage Base -->
    <record id="rule_parameter_us_ut_suta_wage_base" model="hr.rule.parameter">
        <field name="name">US UT Utah SUTA Wage Base</field>
        <field name="code">us_ut_suta_wage_base</field>
        <field name="country_id" ref="base.us"/>
    </record>
    <record id="rule_parameter_us_ut_suta_wage_base_2020" model="hr.rule.parameter.value">
        <field name="parameter_value">36600.0</field>
        <field name="rule_parameter_id" ref="rule_parameter_us_ut_suta_wage_base"/>
        <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
    </record>

    <!-- Rate -->
    <record id="rule_parameter_us_ut_suta_rate" model="hr.rule.parameter">
        <field name="name">US UT Utah SUTA Rate</field>
        <field name="code">us_ut_suta_rate</field>
        <field name="country_id" ref="base.us"/>
    </record>
    <data noupdate="1">
        <record id="rule_parameter_us_ut_suta_rate_2020" model="hr.rule.parameter.value">
            <field name="parameter_value">0.1</field>
            <field name="rule_parameter_id" ref="rule_parameter_us_ut_suta_rate"/>
            <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
        </record>
    </data>
    
    <record id="rule_parameter_us_ut_tax_rate" model="hr.rule.parameter">
        <field name="name">US UT Utah TAX Rate</field>
        <field name="code">us_ut_tax_rate</field>
        <field name="country_id" ref="base.us"/>
    </record>
    <record id="rule_parameter_us_ut_tax_rate_2020" model="hr.rule.parameter.value">
        <field name="parameter_value">0.0495</field>
        <field name="rule_parameter_id" ref="rule_parameter_us_ut_tax_rate"/>
        <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
    </record>

    <record id="rule_parameter_us_ut_sit_allowances_rate" model="hr.rule.parameter">
        <field name="name">US UT Utah Allowances Rate</field>
        <field name="code">us_ut_sit_allowances_rate</field>
        <field name="country_id" ref="base.us"/>
    </record>
    <record id="rule_parameter_us_ut_sit_allowances_rate_2020" model="hr.rule.parameter.value">
        <field name="parameter_value">{
            'single': {
                'weekly' :        7,
                'bi-weekly' :     14,
                'semi-monthly':   15,
                'monthly' :       30,
                'quarterly' :     90,
                'semi-annual':   180,
                'annually':      360,
            },
            'married': {
                'weekly' :        14,
                'bi-weekly' :     28,
                'semi-monthly':   30,
                'monthly' :       60,
                'quarterly' :    180,
                'semi-annual':   360,
                'annually':      720,
            },
            'head_household': {
                'weekly' :        7,
                'bi-weekly' :     14,
                'semi-monthly':   15,
                'monthly' :       30,
                'quarterly' :     90,
                'semi-annual':   180,
                'annually':      360,
            },
        }</field>
        <field name="rule_parameter_id" ref="rule_parameter_us_ut_sit_allowances_rate"/>
        <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
    </record>

    <record id="rule_parameter_us_ut_sit_tax_rate" model="hr.rule.parameter">
        <field name="name">US UT Utah SIT Tax Rate</field>
        <field name="code">us_ut_sit_tax_rate</field>
        <field name="country_id" ref="base.us"/>
    </record>
    <record id="rule_parameter_us_ut_sit_tax_rate_2020" model="hr.rule.parameter.value">
        <field name="parameter_value">{
            'single': {
                'weekly': ((137, 1.3)),
                'bi-weekly': ((274, 1.3)),
                'semi-monthly': ((297, 1.3)),
                'monthly': ((594, 1.3)),
                'quarterly': ((1782, 1.3)),
                'semi-annual': ((3564, 1.3)),
                'annually': ((7128, 1.3)),
            },
            'married': {
                'weekly': ((274, 1.3)),
                'bi-weekly': (548, 1.3),
                'semi-monthly': ((594, 1.3)),
                'monthly': ((1188, 1.3)),
                'quarterly': ((3564, 1.3)),
                'semi-annual': ((7128, 1.3)),
                'annually': ((14256, 1.3)),
            },
            'head_household': {
                'weekly': ((137, 1.3)),
                'bi-weekly': ((274, 1.3)),
                'semi-monthly': ((297, 1.3)),
                'monthly': ((594, 1.3)),
                'quarterly': ((1782, 1.3)),
                'semi-annual': ((3564, 1.3)),
                'annually': ((7128, 1.3)),
            },
        }</field>
        <field name="rule_parameter_id" ref="rule_parameter_us_ut_sit_tax_rate"/>
        <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
    </record>

    <!-- Partners and Contribution Registers -->
    <record id="res_partner_us_ut_dor" model="res.partner">
        <field name="name">US Utah - Employment Security Commission - Unemployment Tax</field>
    </record>

    <record id="res_partner_us_ut_dor_sit" model="res.partner">
        <field name="name">US Utah - Tax Commission - Income Tax</field>
    </record>

    <!-- Categories -->

    <!-- Rules -->
    <record id="hr_payroll_rule_er_us_ut_suta" model="hr.salary.rule">
        <field name="sequence" eval="450"/>
        <field name="struct_id" ref="hr_payroll_structure"/>
        <field name="category_id" ref="hr_payroll_category_er_us_suta"/>
        <field name="name">ER: US UT Utah State Unemployment</field>
        <field name="code">ER_US_UT_SUTA</field>
        <field name="condition_select">python</field>
        <field name="condition_python">result, _ = general_state_unemployment(payslip, categories, worked_days, inputs, wage_base='us_ut_suta_wage_base', rate='us_ut_suta_rate', state_code='UT')</field>
        <field name="amount_select">code</field>
        <field name="amount_python_compute">result, result_rate = general_state_unemployment(payslip, categories, worked_days, inputs, wage_base='us_ut_suta_wage_base', rate='us_ut_suta_rate', state_code='UT')</field>
        <field name="partner_id" ref="res_partner_us_ut_dor"/>
        <field name="appears_on_payslip" eval="False"/>
    </record>

    <record id="hr_payroll_rule_ee_us_ut_sit" model="hr.salary.rule">
        <field name="sequence" eval="195"/>
        <field name="struct_id" ref="hr_payroll_structure"/>
        <field name="category_id" ref="hr_payroll_category_ee_us_sit"/>
        <field name="name">EE: US UT Utah State Income Tax Withholding</field>
        <field name="code">EE_US_UT_SIT</field>
        <field name="condition_select">python</field>
        <field name="condition_python">result, _ = ut_utah_state_income_withholding(payslip, categories, worked_days, inputs)</field>
        <field name="amount_select">code</field>
        <field name="amount_python_compute">result, result_rate = ut_utah_state_income_withholding(payslip, categories, worked_days, inputs)</field>
        <field name="partner_id" ref="res_partner_us_ut_dor_sit"/>
        <field name="appears_on_payslip" eval="True"/>
    </record>

</odoo>