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

    <record id="partner_sunat" model="res.partner">
        <field name="name">SUNAT</field>
    </record>

    <record id="partner_afp" model="res.partner">
        <field name="name">AFP</field>
    </record>

    <record id="structure_type_employee" model="hr.payroll.structure.type">
        <field name="name">Peru Employee (5ta Cat.)</field>
        <field name="default_resource_calendar_id" ref="resource.resource_calendar_std"/>
        <field name="country_id" ref="base.pe"/>
    </record>

    <record id="hr_payroll_structure" model="hr.payroll.structure">
        <field name="name">Peru Employee (5ta Cat.)</field>
        <field name="code">PE5</field>
        <field name="country_id" ref="base.pe"/>
        <field name="type_id" ref="l10n_pe_hr_payroll.structure_type_employee"/>
        <field name="unpaid_work_entry_type_ids" eval="[
            (4, ref('hr_work_entry_contract.work_entry_type_unpaid_leave')),
        ]"/>
    </record>

    <record id="l10n_pe_hr_payroll.structure_type_employee" model="hr.payroll.structure.type">
        <field name="default_struct_id" ref="hr_payroll_structure"/>
    </record>

    <record id="hr_payroll_structure_gratif" model="hr.payroll.structure">
        <field name="name">July/December Gratuity (5ta Cat.)</field>
        <field name="code">PE5GRATIF</field>
        <field name="type_id" ref="l10n_pe_hr_payroll.structure_type_employee"/>
        <field name="country_id" ref="base.pe"/>
        <field name="rule_ids" eval="[]"/>
        <field name="use_worked_day_lines" eval="False"/>
    </record>

    <record id="structure_type_employee_4ta_cat" model="hr.payroll.structure.type">
        <field name="name">Peru Employee (4ta Cat.)</field>
        <field name="default_resource_calendar_id" ref="resource.resource_calendar_std"/>
        <field name="country_id" ref="base.pe"/>
    </record>

    <record id="hr_payroll_structure_4ta_cat" model="hr.payroll.structure">
        <field name="name">Peru Employee (4ta Cat.)</field>
        <field name="country_id" ref="base.pe"/>
        <field name="type_id" ref="l10n_pe_hr_payroll.structure_type_employee_4ta_cat"/>
    </record>

    <record id="l10n_pe_hr_payroll.structure_type_employee_4ta_cat" model="hr.payroll.structure.type">
        <field name="default_struct_id" ref="hr_payroll_structure_4ta_cat"/>
    </record>

    <!-- AFP -->
    <record id="hr_payroll_category_ee_pe_afp" model="hr.salary.rule.category">
        <field name="name">EE: AFP</field>
        <field name="code">EE_PE_AFP</field>
        <field name="parent_id" ref="hr_payroll.DED"/>
    </record>
    <record id="hr_payroll_category_er_pe_afp" model="hr.salary.rule.category">
        <field name="name">ER: AFP</field>
        <field name="code">ER_PE_AFP</field>
        <field name="parent_id" ref="hr_payroll.COMP"/>
    </record>

    <!-- ONP -->
    <record id="hr_payroll_category_ee_pe_onp" model="hr.salary.rule.category">
        <field name="name">EE: ONP</field>
        <field name="code">EE_PE_ONP</field>
        <field name="parent_id" ref="hr_payroll.DED"/>
    </record>
    <record id="hr_payroll_category_er_pe_onp" model="hr.salary.rule.category">
        <field name="name">ER: ONP</field>
        <field name="code">ER_PE_ONP</field>
        <field name="parent_id" ref="hr_payroll.COMP"/>
    </record>

    <!-- IR 5TA CAT -->
    <record id="hr_payroll_category_ee_ir_5ta_cat" model="hr.salary.rule.category">
        <field name="name">EE: IR 5th Cat.</field>
        <field name="code">EE_PE_IR_5TA_CAT</field>
        <field name="parent_id" ref="hr_payroll.DED"/>
    </record>
    <record id="hr_payroll_category_er_ir_5ta_cat" model="hr.salary.rule.category">
        <field name="name">ER: IR 5th Cat.</field>
        <field name="code">ER_PE_IR_5TA_CAT</field>
        <field name="parent_id" ref="hr_payroll.COMP"/>
    </record>

    <!-- IR 4TA CAT -->
    <record id="hr_payroll_category_ee_ir_4ta_cat" model="hr.salary.rule.category">
        <field name="name">EE: IR 4th Cat.</field>
        <field name="code">EE_PE_IR_4TA_CAT</field>
        <field name="parent_id" ref="hr_payroll.DED"/>
    </record>

    <!-- ESSALUD-->
    <record id="hr_payroll_category_ee_essalud" model="hr.salary.rule.category">
        <field name="name">EE: Essalud (rem)</field>
        <field name="code">EE_PE_ESSALUD</field>
        <field name="parent_id" ref="hr_payroll.DED"/>
    </record>
    <record id="hr_payroll_category_er_essalud" model="hr.salary.rule.category">
        <field name="name">EE: Essalud</field>
        <field name="code">ER_PE_ESSALUD</field>
        <field name="parent_id" ref="hr_payroll.COMP"/>
    </record>

    <!-- Extra input & rule -->
    <record id="input_type_extra" model="hr.payslip.input.type">
        <field name="name">Extraordinary Wage</field>
        <field name="code">EXTRA</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_salary_rule_extra" model="hr.salary.rule">
        <field name="condition_select">python</field>
        <field name="condition_python">result = inputs.EXTRA.amount > 0.0 if inputs.EXTRA else False</field>
        <field name="amount_select">code</field>
        <field name="amount_python_compute">result = inputs.EXTRA.amount if inputs.EXTRA else 0</field>
        <field name="code">ALW_EXTRA</field>
        <field name="category_id" ref="hr_payroll.ALW"/>
        <field name="name">Extraordinary Wage</field>
        <field name="sequence" eval="24"/>
        <field name="struct_id" ref="l10n_pe_hr_payroll.hr_payroll_structure"/>
    </record>

    <!-- Bonus input & rule -->
    <record id="input_type_bono" model="hr.payslip.input.type">
        <field name="name">Bonus</field>
        <field name="code">BONO</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_salary_rule_bonus" model="hr.salary.rule">
        <field name="condition_select">python</field>
        <field name="condition_python">result = inputs.BONO.amount > 0.0 if inputs.BONO else False</field>
        <field name="amount_select">code</field>
        <field name="amount_python_compute">result = inputs.BONO.amount if inputs.BONO else 0</field>
        <field name="code">ALW_BONO</field>
        <field name="category_id" ref="hr_payroll.ALW"/>
        <field name="name">Bonus</field>
        <field name="sequence" eval="25"/>
        <field name="struct_id" ref="l10n_pe_hr_payroll.hr_payroll_structure"/>
    </record>

    <!-- Household Allowance -->
    <!-- Parameters -->
    <record id="rule_parameter_pe_min_wage" model="hr.rule.parameter">
        <field name="name">Peru Minimum Wage</field>
        <field name="code">pe_min_wage</field>
        <field name="country_id" ref="base.pe"/>
    </record>
    <record id="rule_parameter_pe_min_wage_2020" model="hr.rule.parameter.value">
        <field name="parameter_value">930.0</field>
        <field name="rule_parameter_id" ref="rule_parameter_pe_min_wage"/>
        <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
    </record>

    <record id="rule_parameter_pe_minor_dependent_rate" model="hr.rule.parameter">
        <field name="name">Peru Minor Dependent Rate</field>
        <field name="code">pe_minor_dependent_rate</field>
        <field name="country_id" ref="base.pe"/>
    </record>
    <record id="rule_parameter_pe_minor_dependent_rate_2020" model="hr.rule.parameter.value">
        <field name="parameter_value">10.0</field>
        <field name="rule_parameter_id" ref="rule_parameter_pe_minor_dependent_rate"/>
        <field name="date_from" eval="datetime(2020, 1, 1).date()"/>
    </record>

    <record id="hr_salary_rule_household_allowance" model="hr.salary.rule">
        <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'), payslip.rule_parameter('pe_minor_dependent_rate')</field>
        <field name="code">BASIC_HOUSEHOLD</field>
        <field name="category_id" ref="hr_payroll.BASIC"/>
        <field name="name">Basic: Household Allowance</field>
        <field name="sequence" eval="5"/>
        <field name="struct_id" ref="l10n_pe_hr_payroll.hr_payroll_structure"/>
    </record>

</odoo>
