<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <!-- Wage Base -->
    <data noupdate="1">
        <record id="rule_parameter_us_ks_suta_wage_base_2020" model="hr.payroll.rate">
            <field name="name">US KS Kansas SUTA Wage Base</field>
            <field name="code">us_ks_suta_wage_base</field>
            <field name="parameter_value">14000.0</field>
            <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
        </record>
    </data>

    <!-- Rate -->
    <data noupdate="1">
        <record id="rule_parameter_us_ks_suta_rate_2020" model="hr.payroll.rate">
            <field name="name">US KS Kansas SUTA Rate</field>
            <field name="code">us_ks_suta_rate</field>
            <field name="parameter_value">2.7</field>
            <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
        </record>
    </data>

    <!-- Allowances -->
    <data noupdate="1">
        <record id="rule_parameter_us_ks_sit_allowances_rate_2020" model="hr.payroll.rate">
            <field name="name">US KS Kansas Allowances Rate</field>
            <field name="code">us_ks_sit_allowances_rate</field>
            <field name="parameter_value">{
                'weekly' :        43.27,
                'bi-weekly' :     86.54,
                'semi-monthly':   93.75,
                'monthly' :      187.50,
                'quarterly' :    562.50,
                'semi-annual':  1125.00,
                'annually':     2250.00,
            }</field>
            <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
        </record>
    </data>

    <!-- Table from percentage table from https://www.ksrevenue.org/pdf/kw100.pdf -->
    <data noupdate="1">
        <record id="rule_parameter_us_ks_sit_tax_rate_2020" model="hr.payroll.rate">
            <field name="name">US KS Kansas SIT Tax Rate</field>
            <field name="code">us_ks_sit_tax_rate</field>
            <field name="parameter_value">{
                'single': {
                    'weekly': (
                        (   58, 0.00,  0.00),
                        (  346, 3.10,  0.00),
                        (  635, 5.25,  8.94),
                        ('inf', 5.70, 24.09),
                    ),
                    'bi-weekly': (
                        (  115, 0.00,  0.00),
                        (  692, 3.10,  0.00),
                        ( 1269, 5.25, 17.88),
                        ('inf', 5.70, 48.17),
                    ),
                    'semi-monthly': (
                        (  125, 0.00,  0.00),
                        (  750, 3.10,  0.00),
                        ( 1375, 5.25, 19.38),
                        ('inf', 5.70, 52.19),
                    ),
                    'monthly': (
                        (  250, 0.00,   0.00),
                        ( 1500, 3.10,   0.00),
                        ( 2750, 5.25,  38.75),
                        ('inf', 5.70, 104.38),
                    ),
                    'quarterly': (
                        (  750, 0.00,   0.00),
                        ( 4500, 3.10,   0.00),
                         (8250, 5.25, 116.25),
                        ('inf', 5.70, 313.13),
                    ),
                    'semi-annual': (
                        ( 1500, 0.00,   0.00),
                        ( 9000, 3.10,   0.00),
                        (16500, 5.25, 232.50),
                        ('inf', 5.70, 626.25),
                    ),
                    'annually': (
                        ( 3000, 0.00,    0.00),
                        (18000, 3.10,    0.00),
                        (33000, 5.25,  465.00),
                        ('inf', 5.70, 1252.50),
                    ),
                },
                'married': {
                    'weekly': (
                        ( 144, 0.00,   0.00),
                        ( 721, 3.10,   0.00),
                        (1298, 5.25,  17.88),
                        ('inf', 5.70, 48.17),
                    ),
                    'bi-weekly': (
                        (  288, 0.00,  0.00),
                        ( 1442, 3.10,  0.00),
                        ( 2596, 5.25, 35.77),
                        ('inf', 5.70, 96.35),
                    ),
                    'semi-monthly': (
                        (  313, 0.00,   0.00),
                        ( 1563, 3.10,   0.00),
                        ( 2813, 5.25,  38.75),
                        ('inf', 5.70, 104.38),
                    ),
                    'monthly': (
                        (  625, 0.00,   0.00),
                        ( 3125, 3.10,   0.00),
                        ( 5625, 5.25,  77.50),
                        ('inf', 5.70, 208.75),
                    ),
                    'quarterly': (
                        ( 1875, 0.00,   0.00),
                        ( 9375, 3.10,   0.00),
                        (16875, 5.25, 232.50),
                        ('inf', 5.70, 626.25),
                    ),
                    'semi-annual': (
                        ( 3750, 0.00,    0.00),
                        (18750, 3.10,    0.00),
                        (33750, 5.25,  465.00),
                        ('inf', 5.70, 1252.50),
                    ),
                    'annually': (
                        ( 7500, 0.00,    0.00),
                        (37500, 3.10,    0.00),
                        (67500, 5.25,  930.00),
                        ('inf', 5.70, 2505.00),
                    ),
                },
            }</field>
            <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
        </record>
    </data>

    <!-- Partners and Contribution Registers -->
    <record id="res_partner_us_ks_dor" model="res.partner">
        <field name="name">US Kansas - Department of Labor - Unemployment Tax</field>
        <field name="supplier">1</field>
    </record>
    <record id="contrib_register_us_ks_dor" model="hr.contribution.register">
        <field name="name">US Kansas - Department of Labor - Unemployment Tax</field>
        <field name="partner_id" ref="res_partner_us_ks_dor"/>
    </record>

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

    <!-- Rules -->
    <record id="hr_payroll_rule_er_us_ks_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 KS Kansas State Unemployment</field>
        <field name="code">ER_US_KS_SUTA</field>
        <field name="condition_select">python</field>
        <field name="condition_python">result, _ = general_state_unemployment(payslip, categories, worked_days, inputs, wage_base='us_ks_suta_wage_base', rate='us_ks_suta_rate', state_code='KS')</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_ks_suta_wage_base', rate='us_ks_suta_rate', state_code='KS')</field>
        <field name="register_id" ref="contrib_register_us_ks_dor"/>
        <field name="appears_on_payslip" eval="False"/>
    </record>

    <record id="hr_payroll_rule_ee_us_ks_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 KS Kansas State Income Tax Withholding</field>
        <field name="code">EE_US_KS_SIT</field>
        <field name="condition_select">python</field>
        <field name="condition_python">result, _ = ks_kansas_state_income_withholding(payslip, categories, worked_days, inputs)</field>
        <field name="amount_select">code</field>
        <field name="amount_python_compute">result, result_rate = ks_kansas_state_income_withholding(payslip, categories, worked_days, inputs)</field>
        <field name="register_id" ref="contrib_register_us_ks_dor_sit"/>
        <field name="appears_on_payslip" eval="True"/>
    </record>

</odoo>