<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

    <!-- Parameters -->
    <record id="rule_parameter_pe_uit" model="hr.rule.parameter">
        <field name="name">Peru UIT</field>
        <field name="code">pe_uit</field>
        <field name="country_id" ref="base.pe"/>
    </record>
    <record id="rule_parameter_pe_uit_2020" model="hr.rule.parameter.value">
        <field name="parameter_value">4400.0</field>
        <field name="rule_parameter_id" ref="rule_parameter_pe_uit"/>
        <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
    </record>

    <record id="rule_parameter_ee_ir_5ta_cat" model="hr.rule.parameter">
        <field name="name">EE: IR 5ta Cat.</field>
        <field name="code">ee_ir_5ta_cat</field>
        <field name="country_id" ref="base.pe"/>
    </record>
    <!-- 2015 chart -->
    <record id="rule_parameter_ee_ir_5ta_cat_2020" model="hr.rule.parameter.value">
        <field name="parameter_value">[
        (  5.0,   8.0),
        ( 20.0,  14.0),
        ( 35.0,  17.0),
        ( 45.0,  20.0),
        ('inf',  30.0),
        ]</field>
        <field name="rule_parameter_id" ref="rule_parameter_ee_ir_5ta_cat"/>
        <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
    </record>

    <record id="rule_parameter_ee_ir_5ta_cat_ley_29351" model="hr.rule.parameter">
        <field name="name">EE: IR 5ta Cat. Bonificación Extraordinaria (Ley 29351)</field>
        <field name="code">ee_ir_5ta_cat_ley_29351</field>
        <field name="country_id" ref="base.pe"/>
    </record>
    <record id="rule_parameter_ee_ir_5ta_cat_ley_29351_2020" model="hr.rule.parameter.value">
        <field name="parameter_value">9.0</field>
        <field name="rule_parameter_id" ref="rule_parameter_ee_ir_5ta_cat_ley_29351"/>
        <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
    </record>


    <!-- EE Rules -->
    <record id="input_type_ee_ir_5ta_cat" model="hr.payslip.input.type">
        <field name="name">Manual IR 5th Cat.</field>
        <field name="code">EE_PE_IR_5TA_CAT</field>
        <field name="country_id" ref="base.pe" />
        <field name="struct_ids" eval="[
            (4, ref('l10n_pe_hr_payroll.hr_payroll_structure')),
        ]" />
    </record>

    <record id="hr_payroll_rule_ee_ir_5ta_cat" model="hr.salary.rule">
        <field name="sequence" eval="196"/>
        <field name="struct_id" ref="hr_payroll_structure"/>
        <field name="category_id" ref="hr_payroll_category_ee_ir_5ta_cat"/>
        <field name="name">EE: PE IR 5th Cat.</field>
        <field name="code">EE_PE_IR_5TA_CAT</field>
        <field name="condition_select">python</field>
        <field name="condition_python">result, _ = ir_5ta_cat(payslip, categories, worked_days, inputs)</field>
        <field name="amount_select">code</field>
        <field name="amount_python_compute">result, result_rate = ir_5ta_cat(payslip, categories, worked_days, inputs)</field>
        <field name="appears_on_payslip" eval="True"/>
        <field name="partner_id" ref="partner_sunat"/>
    </record>

    <!-- July/December Gratuity -->
    <record id="input_type_gratif_months" model="hr.payslip.input.type">
        <field name="name">Gratif Full Months</field>
        <field name="code">MONTHS</field>
        <field name="country_id" ref="base.pe" />
        <field name="struct_ids" eval="[
            (4, ref('l10n_pe_hr_payroll.hr_payroll_structure_gratif')),
        ]" />
    </record>

    <record id="hr_payroll_rule_ir_5ta_cat_gratif" model="hr.salary.rule">
        <field name="sequence" eval="80"/>
        <field name="struct_id" ref="hr_payroll_structure_gratif"/>
        <field name="category_id" ref="hr_payroll.ALW"/>
        <field name="name">Gratif</field>
        <field name="code">ALW_GRATIF</field>
        <field name="condition_select">none</field>
        <field name="amount_select">code</field>
        <field name="amount_python_compute">result = payslip.paid_amount</field>
        <field name="appears_on_payslip" eval="True"/>
    </record>

    <record id="hr_payroll_rule_ir_5ta_cat_gratif_household" model="hr.salary.rule">
        <field name="sequence" eval="81"/>
        <field name="struct_id" ref="hr_payroll_structure_gratif"/>
        <field name="category_id" ref="hr_payroll.ALW"/>
        <field name="name">Household Allowance</field>
        <field name="code">ALW_GRATIF_HOUSEHOLD</field>
        <field name="condition_select">python</field>
        <field name="condition_python">result = contract.pe_payroll_config_value('has_minor_dependent')</field>
        <field name="amount_select">code</field>
        <field name="amount_python_compute">result, result_rate = (payslip.rule_parameter('pe_min_wage')*inputs.MONTHS.amount / 6.0), payslip.rule_parameter('pe_minor_dependent_rate')</field>
        <field name="appears_on_payslip" eval="True"/>
    </record>

    <record id="hr_payroll_rule_ir_5ta_cat_gratif_bono" model="hr.salary.rule">
        <field name="sequence" eval="90"/>
        <field name="struct_id" ref="hr_payroll_structure_gratif"/>
        <field name="category_id" ref="hr_payroll.ALW"/>
        <field name="name">Gratif Bonifextra</field>
        <field name="code">ALW_GRATIF_BONIFEXTRA</field>
        <field name="condition_select">python</field>
        <field name="condition_python">result = categories.ALW</field>
        <field name="amount_select">code</field>
        <field name="amount_python_compute">result, result_rate = categories.ALW, payslip.rule_parameter('er_essalud')</field>
        <field name="appears_on_payslip" eval="True"/>
    </record>

    <record id="hr_payroll_rule_ir_5ta_cat_gratif_net" model="hr.salary.rule">
        <field name="sequence" eval="200"/>
        <field name="struct_id" ref="hr_payroll_structure_gratif"/>
        <field name="category_id" ref="hr_payroll.NET"/>
        <field name="name">Net Gratif</field>
        <field name="code">NET</field>
        <field name="condition_select">none</field>
        <field name="amount_select">code</field>
        <field name="amount_python_compute">result = categories.BASIC + categories.ALW + categories.DED</field>
        <field name="appears_on_payslip" eval="True"/>
    </record>

</odoo>
