<?xml version='1.0' encoding='UTF-8' ?>
<odoo>
    <record id="hr_accrual_level_view_form" model="ir.ui.view">
        <field name="name">hr.leave.accrual.level.form</field>
        <field name="model">hr.leave.accrual.level</field>
        <field name="arch" type="xml">
            <form string="Accrual Level">
                <sheet>
                    <div colspan="2">
                        <field name="can_modify_value_type" invisible="1"/>
                    </div>
                    <div class="o_accrual_level_form">
                        <group class="o_accrual" string="Accrual Level Options">
                            <label class="fw-bold" for="added_value" string="Set the employee accrual frequency :"/>
                            <span>
                                <field nolabel="1" class="me-1 o_field_accrual" name="added_value"
                                       widget="float_without_trailing_zeros"/>
                                <field nolabel="1" class="me-1 o_field_accrual" name="added_value_type"
                                       readonly="not can_modify_value_type"/>
                                <field nolabel="1" class="o_field_accrual" name="frequency"/>
                                <span name="weekly" invisible="frequency != 'weekly'">
                                    on
                                    <field nolabel="1" name="week_day" class="o_field_accrual" required="frequency == 'weekly'" placeholder="select a weekday"/>
                                </span>
                                <span name="monthly" invisible="frequency != 'monthly'">
                                    on the
                                    <field nolabel="1" name="first_day" class="o_field_accrual" required="frequency == 'monthly'" placeholder="select a day"/>
                                    of the month.
                                </span>
                                <span name="bimonthly" invisible="frequency != 'bimonthly'" style="width: 100%">
                                    on the
                                    <field nolabel="1" name="first_day" class="o_field_accrual" required="frequency == 'bimonthly'" placeholder="select a day"/>
                                    and the
                                    <field nolabel="1" name="second_day" class="o_field_accrual" required="frequency == 'bimonthly'" placeholder="select a day"/>
                                    of the month
                                </span>
                                <span name="biyearly" invisible="frequency != 'biyearly'">
                                    on the
                                    <field nolabel="1" name="first_month_day" class="o_field_accrual" widget="day_selection" month_field="first_month" placeholder="select a day" required="frequency == 'biyearly'"/>
                                    of
                                    <field name="first_month" class="o_field_accrual" placeholder="select a month" required="frequency == 'biyearly'"/>
                                    and the
                                    <field nolabel="1" name="second_month_day" class="o_field_accrual" widget="day_selection" month_field="second_month" placeholder="select a day" required="frequency == 'biyearly'"/>
                                    of
                                    <field nolabel="1" name="second_month" class="o_field_accrual" placeholder="select a month" required="frequency == 'biyearly'"/>
                                </span>
                                <span name="yearly" invisible="frequency != 'yearly'">
                                    on the
                                    <field nolabel="1" name="yearly_day" class="o_field_accrual" widget="day_selection" month_field="yearly_month" required="frequency == 'yearly'" placeholder="select a day"/>
                                    of
                                    <field nolabel="1" name="yearly_month" class="o_field_accrual" required="frequency == 'yearly'" placeholder="select a month"/>
                                </span>
                            </span>
                            <label class="fw-bold" for="milestone_date" string="This milestone will be reached :"/>
                            <span name="milestone_date">
                                <field nolabel="1" class="ms-1" name="milestone_date"
                                       widget="radio_followed_by_element"
                                       options="{'links': {'after': 'milestone_date_after'}, 'observe': 'milestone_date'}"/>
                                <span id="milestone_date_after">
                                    <field nolabel="1" class="ms-1 me-1 o_field_accrual" name="start_count"/>
                                    <field nolabel="1" class="me-1 o_field_accrual" name="start_type"/>
                                    from the start of allocation
                                </span>
                            </span>
                        </group>
                        <group class="o_accrual" invisible="not can_be_carryover" string="Carry Over Options">
                            <label class="fw-bold" for="action_with_unused_accruals" string="After a year, unused time off will be :"/>
                            <span>
                                <span name="unused_accruals">
                                    <field nolabel="1" class="ms-1" name="action_with_unused_accruals"
                                           widget="radio"
                                           readonly="not can_be_carryover"/>
                                </span>
                            </span>
                            <label class="fw-bold" invisible="action_with_unused_accruals == 'lost'" for="carryover_options" string="How much time can be carried over :"/>
                            <span invisible="action_with_unused_accruals == 'lost'" id="unused_accruals_all">
                                <span name="carryover_options">
                                    <field nolabel="1" class="ms-1" name="carryover_options"
                                           widget="radio_followed_by_element"
                                           options="{'links': {'limited': 'carryover_options_limited'}, 'observe': 'carryover_options'}"/>
                                    <span id="carryover_options_limited" readonly="1">
                                        <field nolabel="1" class="ms-1 me-1 o_field_accrual" name="postpone_max_days"/>
                                        <field nolabel="1" class="o_field_accrual" name="added_value_type" readonly="1"/>
                                    </span>
                                </span>
                            </span>
                            <label class="fw-bold" invisible="action_with_unused_accruals == 'lost'" for="accrual_validity" string="Define a carry over validity?"/>
                            <span invisible="action_with_unused_accruals == 'lost'" class="d-flex">
                                <field nolabel="1" class="ms-1" name="accrual_validity"/>
                                <span invisible="not accrual_validity">
                                    The days carried over will be effective for
                                    <field nolabel="1" class="me-1 o_field_accrual" name="accrual_validity_count"/>
                                    <field nolabel="1" class="me-1 o_field_accrual" name="accrual_validity_type"/>
                                </span>
                            </span>
                        </group>
                        <group string="Cap Options" class="o_accrual">
                            <label class="fw-bold" for="cap_accrued_time_yearly" string="Define a yearly cap?"/>
                            <span>
                                <field nolabel="1" class="ms-1" name="cap_accrued_time_yearly"/>
                                <span invisible="not cap_accrued_time_yearly">
                                    Accrual will stop until next carry-over date if accrued time's reach
                                    <field nolabel="1" class="me-1 o_field_accrual" name="maximum_leave_yearly"
                                           widget="float_without_trailing_zeros"/>
                                    <field nolabel="1" class="o_field_accrual" name="added_value_type" readonly="1"/>.
                                </span>
                            </span>
                            <label class="fw-bold" for="cap_accrued_time" string="Define a balance cap?"/>
                            <span>
                                <field nolabel="1" class="ms-1" name="cap_accrued_time"/>
                                <span invisible="not cap_accrued_time">
                                    The plan will be on hold if the balance reach
                                    <field nolabel="1" class="me-1 o_field_accrual" name="maximum_leave"
                                           widget="float_without_trailing_zeros"/>
                                    <field nolabel="1" class="o_field_accrual" name="added_value_type" readonly="1"/> of available time.
                                </span>
                            </span>
                        </group>
                    </div>
                </sheet>
                <footer>
                    <button string="Save" type="object" special="save" class="btn btn-primary"/>
                    <button string="Save &amp; New" type="object" name="action_save_new" class="btn btn-primary"
                            invisible="not context.get('new')"/>
                    <button string="Discard" special="cancel" class="btn btn-secondary"/>
                    <button string="Delete" type="object" name="unlink" class="btn btn-danger ms-auto"
                            invisible="context.get('new')"/>
                </footer>
            </form>
        </field>
    </record>
    <record id="hr_accrual_plan_view_tree" model="ir.ui.view">
        <field name="name">hr.leave.accrual.plan.list</field>
        <field name="model">hr.leave.accrual.plan</field>
        <field name="arch" type="xml">
            <list string="Accrual Plans" sample="1">
                <field name="name"/>
                <field name="level_count"/>
                <field name="employees_count"/>
            </list>
        </field>
    </record>
    <record id="hr_accrual_plan_view_form" model="ir.ui.view">
        <field name="name">hr.leave.accrual.plan.form</field>
        <field name="model">hr.leave.accrual.plan</field>
        <field name="arch" type="xml">
            <form string="Accrual Plan" class="o_accrual_plan_form">
                <field name="active" invisible="1"/>
                <field name="show_transition_mode" invisible="1"/>
                <sheet>
                    <div class="oe_button_box" name="button_box" invisible="not id">
                        <button name="action_open_accrual_plan_employees" type="object" class="oe_stat_button"
                                icon="fa-users" invisible="employees_count == 0" groups="hr.group_hr_user">
                            <field name="employees_count" widget="statinfo"/>
                        </button>
                    </div>
                    <widget name="web_ribbon" title="Archived" bg_color="bg-danger" invisible="active"/>
                    <div>
                        <div class="d-flex flex-direction-row o_accrual_plan_settings">
                            <div class="w-100">
                                <div class="oe_title w-50">
                                    <label class="fw-bold" for="name" string="Title"/>
                                    <h1><field name="name" placeholder="e.g. Seniority Plan, PTO, RTT, ..." required="id"/></h1>
                                    <group groups="base.group_multi_company">
                                        <field name="company_id" options="{'no_create': True}"  groups="base.group_multi_company" placeholder="Visible to all"/>
                                    </group>
                                </div>
                                <group string="Configuration" class="mt-0 o_accrual">
                                    <label class="fw-bold" for="accrued_gain_time" string="When the time is accrued?"/>
                                    <field nolabel="1" class="ms-1" name="accrued_gain_time" widget="radio"/>
                                    <label class="fw-bold" invisible="accrued_gain_time == 'start'" for="is_based_on_worked_time" string="It is based on worked time?"/>
                                    <span invisible="accrued_gain_time == 'start'">
                                        <field class="o_field_radio ms-1" name="is_based_on_worked_time" widget="boolean_radio" options="{
                                                    'yes_label_element_id': 'is_based_on_worked_time_yes',
                                                    'no_label_element_id': 'is_based_on_worked_time_no'
                                                }" readonly="accrued_gain_time == 'start'"/>
                                        <template id="is_based_on_worked_time_yes">Yes, consider the worked hours, excluding any time off taken during that period.
                                        </template>
                                        <template id="is_based_on_worked_time_no">No, always consider the entire accrual period (whole calendar days).
                                        </template>
                                    </span>
                                    <label class="fw-bold" for="can_be_carryover"
                                           string="Do you need a carry-over of the accrued days from one year to another?"/>
                                    <span>
                                        <field class="ms-1" name="can_be_carryover"/>
                                    </span>
                                    <label class="fw-bold" invisible="not can_be_carryover" for="carryover_date"
                                           string="When do you want the accrued time left to be carried-over?"/>
                                    <span name="carryover" invisible="not can_be_carryover">
                                        <field class="ms-1" name="carryover_date"
                                               widget="radio_followed_by_element"
                                               options="{'links': {'other': 'carryover_custom_date'}, 'observe': 'carryover'}"/>
                                        <span id="carryover_custom_date">
                                            : the
                                            <field name="carryover_day" widget="day_selection" month_field="carryover_month" placeholder="select a day"
                                                   required="carryover_date == 'other'"/>
                                            of
                                            <field name="carryover_month" placeholder="select a month"
                                                   required="carryover_date == 'other'"/>
                                        </span>
                                    </span>
                                    <label class="fw-bold" invisible="not show_transition_mode" for="transition_mode" string="Switch employees to the new accrual level:"/>
                                    <span invisible="not show_transition_mode">
                                        <field class="ms-1" name="transition_mode" widget="radio"/>
                                    </span>
                                </group>
                            </div>
                        </div>
                        <div class="o_accrual_plan_levels border rounded-3 d-flex mt-2 flex-direction-column align-items-center flex-1 overflow-hidden">
                            <div class="o_accrual_levels_scrollable w-100 h-100 d-flex align-content-center">
                                <div class="o_view_nocontent top-0" style="position: relative;" invisible="level_ids">
                                    <div class="o_nocontent_help">
                                        <p class="o_view_nocontent_smiling_face">
                                            No milestones on the plan yet. Let's create a new one
                                        </p>
                                        <button name="action_create_accrual_plan_level" type="object"
                                                class="btn btn-primary"
                                                string="Create a milestone"/>
                                    </div>
                                </div>
                                <field name="level_ids" widget="accrual_levels" invisible="not level_ids"/>
                            </div>
                        </div>
                    </div>
                </sheet>
            </form>
        </field>
    </record>
    <record id="hr_accrual_plan_view_search" model="ir.ui.view">
        <field name="name">hr.leave.accrual.plan.search</field>
        <field name="model">hr.leave.accrual.plan</field>
        <field name="arch" type="xml">
            <search string="Accrual Plan">
                <field name="name"/>
                <filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
                <filter string="Company" name='company_id' context="{'group_by':'company_id'}"
                        groups="base.group_multi_company"/>
            </search>
        </field>
    </record>

    <record id="open_view_accrual_plans" model="ir.actions.act_window">
        <field name="name">Accrual Plans</field>
        <field name="res_model">hr.leave.accrual.plan</field>
        <field name="view_mode">list,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create an Accrual Plan
            </p>
            <p>
                Use accrual plans to give determined amount of time following the rules you define
            </p>
        </field>
    </record>
</odoo>
