<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <!-- Wage Base -->
    <data noupdate="1">
        <record id="rule_parameter_us_ia_suta_wage_base_2020" model="hr.payroll.rate">
            <field name="name">US IA Iowa SUTA Wage Base</field>
            <field name="code">us_ia_suta_wage_base</field>
            <field name="parameter_value">31600.0</field>
            <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
        </record>
        <record id="rule_parameter_us_ia_suta_wage_base_2021" model="hr.payroll.rate">
            <field name="name">US IA Iowa SUTA Wage Base</field>
            <field name="code">us_ia_suta_wage_base</field>
            <field name="parameter_value">32400.0</field>
            <field name="date_from" eval="datetime(2021, 1, 1).date()"/>
        </record>
    </data>

    <!-- Rate -->
    <data noupdate="1">
        <record id="rule_parameter_us_ia_suta_rate_2020" model="hr.payroll.rate">
            <field name="name">US IA Iowa SUTA Rate</field>
            <field name="code">us_ia_suta_rate</field>
            <field name="parameter_value">1.0</field>
            <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
        </record>
    </data>

    <data noupdate="1">
        <!-- https://tax.iowa.gov/sites/default/files/idr/documents/WH/IA%20Withholding%20Formula%20and%20Instructions%20TY2020.pdf -->
        <!-- Table from page 2.-->

        <record id="rule_parameter_us_ia_sit_tax_rate_2020" model="hr.payroll.rate">
            <field name="name">US IA Iowa SIT Tax Rate</field>
            <field name="code">us_ia_sit_tax_rate</field>
            <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="date_from" eval="datetime(2020, 1, 1).date()"/>
        </record>
        <record id="rule_parameter_us_ia_sit_tax_rate_2021" model="hr.payroll.rate">
            <field name="name">US IA Iowa SIT Tax Rate</field>
            <field name="code">us_ia_sit_tax_rate</field>
            <field name="parameter_value">{
                'weekly':       (
                    (  32.23, 0.0033,  0.00),
                    (  64.46, 0.0067,  0.11),
                    ( 128.92, 0.0225,  0.33),
                    ( 290.08, 0.0414,  1.78),
                    ( 483.46, 0.0563,  8.45),
                    ( 644.62, 0.0596, 19.34),
                    ( 966.92, 0.0625, 28.95),
                    (1450.38, 0.0744, 49.09),
                    (  'inf', 0.0853, 85.06),
                ),
                'bi-weekly':    (
                    (  64.46, 0.0033,   0.00),
                    ( 128.92, 0.0067,   0.21),
                    ( 257.85, 0.0225,   0.64),
                    ( 580.15, 0.0414,   3.54),
                    ( 966.92, 0.0563,  16.88),
                    (1289.23, 0.0596,  38.66),
                    (1933.85, 0.0625,  57.87),
                    (2900.77, 0.0744,  98.16),
                    (  'inf', 0.0853, 170.10),
                ),
                'semi-monthly': (
                    (  69.83, 0.0033,   0.00),
                    ( 139.67, 0.0067,   0.23),
                    ( 279.33, 0.0225,   0.70),
                    ( 628.50, 0.0414,   3.84),
                    (1047.50, 0.0563,  18.30),
                    (1396.67, 0.0596,  41.89),
                    (2095.00, 0.0625,  62.70),
                    (3142.50, 0.0744, 106.35),
                    (  'inf', 0.0853, 184.28),
                ),
                'monthly':      (
                    ( 139.67, 0.0033,   0.00),
                    ( 279.33, 0.0067,   0.46),
                    ( 558.67, 0.0225,   1.40),
                    (1257.00, 0.0414,   7.69),
                    (2095.00, 0.0563,  36.60),
                    (2793.33, 0.0596,  83.78),
                    (4190.00, 0.0625, 125.40),
                    (6285.00, 0.0744, 212.69),
                    (  'inf', 0.0853, 368.56),
                ),
                'annual':       (
                    ( 1676.00, 0.0033,    0.00),
                    ( 3352.00, 0.0067,    5.53),
                    ( 6704.00, 0.0225,   16.76),
                    (15084.00, 0.0414,   92.18),
                    (25140.00, 0.0563,  439.11),
                    (33520.00, 0.0596, 1005.26),
                    (50280.00, 0.0625, 1504.71),
                    (75420.00, 0.0744, 2552.21),
                    (   'inf', 0.0853, 4422.63),
                ),
            }</field>
            <field name="date_from" eval="datetime(2021, 1, 1).date()"/>
        </record>
    </data>

    <data noupdate="1">
        <!-- https://tax.iowa.gov/sites/default/files/idr/documents/WH/IA%20Withholding%20Formula%20and%20Instructions%20TY2020.pdf-->
        <!-- Step 2 -->
        <record id="rule_parameter_us_ia_sit_standard_deduction_rate_2020" model="hr.payroll.rate">
            <field name="name">US IA Iowa Standard Deduction Rate</field>
            <field name="code">us_ia_sit_standard_deduction_rate</field>
            <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="date_from" eval="datetime(2020, 1, 1).date()"/>
        </record>
        <record id="rule_parameter_us_ia_sit_standard_deduction_rate_2021" model="hr.payroll.rate">
            <field name="name">US IA Iowa Standard Deduction Rate</field>
            <field name="code">us_ia_sit_standard_deduction_rate</field>
            <field name="parameter_value">{
                'weekly':       (  40.96,  100.77),
                'bi-weekly':    (  81.92,  201.54),
                'semi-monthly': (  88.75,  218.33),
                'monthly':      ( 177.50,  436.67),
                'annually':     (2130.00, 5240.00),
            }</field>
            <field name="date_from" eval="datetime(2021, 1, 1).date()"/>
        </record>
    </data>

    <data noupdate="1">
        <!-- https://tax.iowa.gov/sites/default/files/idr/documents/WH/IA%20Withholding%20Formula%20and%20Instructions%20TY2020.pdf -->
        <!-- Step 4 -->
        <record id="rule_parameter_us_ia_sit_deduction_allowance_rate_2020" model="hr.payroll.rate">
            <field name="name">US IA Iowa Deduction Allowance Rate</field>
            <field name="code">us_ia_sit_deduction_allowance_rate</field>
            <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="date_from" eval="datetime(2020, 1, 1).date()"/>
        </record>
    </data>

    <!-- Partners and Contribution Registers -->
    <record id="res_partner_us_ia_dor" model="res.partner">
        <field name="name">US Iowa - Workforce Development - Unemployment Tax</field>
        <field name="supplier">1</field>
    </record>
    <record id="contrib_register_us_ia_dor" model="hr.contribution.register">
        <field name="name">US Iowa - Workforce Development - Unemployment Tax</field>
        <field name="partner_id" ref="res_partner_us_ia_dor"/>
    </record>

    <record id="res_partner_us_ia_dor_sit" model="res.partner">
        <field name="name">US Iowa - Department of Revenue - Income Tax</field>
        <field name="supplier">1</field>
    </record>
    <record id="contrib_register_us_ia_dor_sit" model="hr.contribution.register">
        <field name="name">US Iowa - Department of Revenue - Income Tax</field>
        <field name="partner_id" ref="res_partner_us_ia_dor_sit"/>
    </record>

    <!-- Categories -->

    <!-- Rules -->
    <record id="hr_payroll_rule_er_us_ia_suta" model="hr.salary.rule">
        <field name="sequence" eval="450"/>
        <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="register_id" ref="contrib_register_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="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="register_id" ref="contrib_register_us_ia_dor_sit"/>
        <field name="appears_on_payslip" eval="True"/>
    </record>

</odoo>