<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <!-- Wage Base -->
    <record id="rule_parameter_us_ia_suta_wage_base" model="hr.rule.parameter">
        <field name="name">US IA Iowa SUTA Wage Base</field>
        <field name="code">us_ia_suta_wage_base</field>
        <field name="country_id" ref="base.us"/>
    </record>
    <record id="rule_parameter_us_ia_suta_wage_base_2020" model="hr.rule.parameter.value">
        <field name="parameter_value">31600.0</field>
        <field name="rule_parameter_id" ref="rule_parameter_us_ia_suta_wage_base"/>
        <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
    </record>

    <!-- Rate -->
    <record id="rule_parameter_us_ia_suta_rate" model="hr.rule.parameter">
        <field name="name">US IA Iowa SUTA Rate</field>
        <field name="code">us_ia_suta_rate</field>
        <field name="country_id" ref="base.us"/>
    </record>
    <data noupdate="1">
        <record id="rule_parameter_us_ia_suta_rate_2020" model="hr.rule.parameter.value">
            <field name="parameter_value">1.0</field>
            <field name="rule_parameter_id" ref="rule_parameter_us_ia_suta_rate"/>
            <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
        </record>
    </data>

    <record id="rule_parameter_us_ia_sit_tax_rate" model="hr.rule.parameter">
        <field name="name">US IA Iowa SIT Tax Rate</field>
        <field name="code">us_ia_sit_tax_rate</field>
        <field name="country_id" ref="base.us"/>
    </record>
    <record id="rule_parameter_us_ia_sit_tax_rate_2020" model="hr.rule.parameter.value">
        <field name="parameter_value">{
            'daily':        (
                (  5.69, 0.0033,  0.00),
                ( 11.38, 0.0067,  0.02),
                ( 22.76, 0.0225,  0.06),
                ( 51.22, 0.0414,  0.32),
                ( 85.36, 0.0563,  1.50),
                (113.81, 0.0596,  3.42),
                (170.71, 0.0625,  5.12),
                (256.07, 0.0744,  8.68),
                ( 'inf', 0.0853, 15.03),
            ),
            'weekly':       (
                (  28.46, 0.0033,  0.00),
                (  56.90, 0.0067,  0.09),
                ( 113.81, 0.0225,  0.28),
                ( 256.08, 0.0414,  1.56),
                ( 426.79, 0.0563,  7.45),
                ( 569.04, 0.0596, 17.06),
                ( 853.56, 0.0625, 25.54),
                (1280.35, 0.0744, 43.32),
                (  'inf', 0.0853, 75.07),
            ),
            'bi-weekly':    (
                (  56.92, 0.0033,   0.00),
                ( 113.81, 0.0067,   0.19),
                ( 227.62, 0.0225,   0.57),
                ( 512.15, 0.0414,   3.13),
                ( 853.58, 0.0563,  14.91),
                (1138.08, 0.0596,  34.13),
                (1707.12, 0.0625,  51.09),
                (2560.69, 0.0744,  86.66),
                (  'inf', 0.0853, 150.17),
            ),
            'semi-monthly': (
                (  61.67, 0.0033,   0.00),
                (  23.29, 0.0067,   0.20),
                ( 246.58, 0.0225,   0.61),
                ( 554.83, 0.0414,   3.38),
                ( 924.71, 0.0563,  16.14),
                (1232.92, 0.0596,  36.96),
                (1849.38, 0.0625,  55.33),
                (2774.08, 0.0744,  93.86),
                (  'inf', 0.0853, 162.66),
            ),
            'monthly':      (
                ( 123.33, 0.0033,   0.00),
                ( 246.58, 0.0067,   0.41),
                ( 493.17, 0.0225,   1.24),
                (1109.67, 0.0414,   6.79),
                (1849.42, 0.0563,  32.31),
                (2465.83, 0.0596,  73.96),
                (3698.75, 0.0625, 110.70),
                (5548.17, 0.0744, 187.76),
                (  'inf', 0.0853, 325.36),
            ),
            'annual':       (
                ( 1480.00, 0.0033,    0.00),
                ( 2959.00, 0.0067,    4.88),
                ( 5918.00, 0.0225,   14.79),
                (13316.00, 0.0414,   81.37),
                (22193.00, 0.0563,  387.65),
                (29590.00, 0.0596,  887.43),
                (44385.00, 0.0625, 1328.29),
                (66578.00, 0.0744, 2252.98),
                (   'inf', 0.0853, 3904.14),
            ),
        }</field>
        <field name="rule_parameter_id" ref="rule_parameter_us_ia_sit_tax_rate"/>
        <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
    </record>

    <record id="rule_parameter_us_ia_sit_standard_deduction_rate" model="hr.rule.parameter">
        <field name="name">US IA Iowa Standard Deduction Rate</field>
        <field name="code">us_ia_sit_standard_deduction_rate</field>
        <field name="country_id" ref="base.us"/>
    </record>
    <record id="rule_parameter_us_ia_sit_standard_deduction_rate_2020" model="hr.rule.parameter.value">
        <field name="parameter_value">{
            'daily':        (   7.23,   17.81),
            'weekly':       (  36.15,   89.04),
            'bi-weekly':    (  72.31,  178.08),
            'semi-monthly': (  78.33,  192.92),
            'monthly':      ( 156.67,  385.83),
            'annually':     (1880.00, 4630.00),
        }</field>
        <field name="rule_parameter_id" ref="rule_parameter_us_ia_sit_standard_deduction_rate"/>
        <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
    </record>

    <record id="rule_parameter_us_ia_sit_deduction_allowance_rate" model="hr.rule.parameter">
        <field name="name">US IA Iowa Deduction Allowance Rate</field>
        <field name="code">us_ia_sit_deduction_allowance_rate</field>
        <field name="country_id" ref="base.us"/>
    </record>
    <record id="rule_parameter_us_ia_sit_deduction_allowance_rate_2020" model="hr.rule.parameter.value">
        <field name="parameter_value">{
            'daily':         0.15,
            'weekly':        0.77,
            'bi-weekly':     1.54,
            'semi-monthly':  1.67,
            'monthly':       3.33,
            'annually':     40.00,
        }</field>
        <field name="rule_parameter_id" ref="rule_parameter_us_ia_sit_deduction_allowance_rate"/>
        <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
    </record>

    <!-- Partners and Contribution Registers -->
    <record id="res_partner_us_ia_dor" model="res.partner">
        <field name="name">US Iowa - Department of Economic Security (IDES) - Unemployment Tax</field>
    </record>

    <record id="res_partner_us_ia_dor_sit" model="res.partner">
        <field name="name">US Iowa - Department of Revenue (IDOR) - Income Tax</field>
    </record>

    <!-- Categories -->

    <!-- Rules -->
    <record id="hr_payroll_rule_er_us_ia_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 IA Iowa State Unemployment</field>
        <field name="code">ER_US_IA_SUTA</field>
        <field name="condition_select">python</field>
        <field name="condition_python">result, _ = general_state_unemployment(payslip, categories, worked_days, inputs, wage_base='us_ia_suta_wage_base', rate='us_ia_suta_rate', state_code='IA')</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_ia_suta_wage_base', rate='us_ia_suta_rate', state_code='IA')</field>
        <field name="partner_id" ref="res_partner_us_ia_dor"/>
        <field name="appears_on_payslip" eval="False"/>
    </record>

    <record id="hr_payroll_rule_ee_us_ia_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 IA Iowa State Income Tax Withholding</field>
        <field name="code">EE_US_IA_SIT</field>
        <field name="condition_select">python</field>
        <field name="condition_python">result, _ = ia_iowa_state_income_withholding(payslip, categories, worked_days, inputs)</field>
        <field name="amount_select">code</field>
        <field name="amount_python_compute">result, result_rate = ia_iowa_state_income_withholding(payslip, categories, worked_days, inputs)</field>
        <field name="partner_id" ref="res_partner_us_ia_dor_sit"/>
        <field name="appears_on_payslip" eval="True"/>
    </record>

</odoo>