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

    <record id="view_hr_leave_allocation_filter" model="ir.ui.view">
        <field name="name">hr.holidays.filter_allocations</field>
        <field name="model">hr.leave.allocation</field>
        <field name="arch" type="xml">
            <search string="Search allocations">
                <field name="name"/>
                <field name="accrual"/>
                <filter domain="[('state','in',('confirm', 'validate1'))]" string="To Approve" name="approve"/>
                <filter string="Approved Allocations" domain="[('state', '=', 'validate')]" name="validated"/>
                <filter string="Accrual Allocations" domain="[('accrual', '=', True)]" name="accrual_allocation"/>
                <separator/>
                <filter name="active_types" string="Active Types" domain="[('holiday_status_id.active', '=', True)]" help="Filters only on allocations that belong to an leave type that is 'active' (active field is True)"/>
                <separator/>
                <filter string="Unread Messages" name="message_needaction" domain="[('message_needaction','=',True)]"/>
                <separator/>
                <filter string="My Department Leaves" name="department" domain="[('department_id.member_ids.user_id', '=', uid)]" help="My Department Leaves"/>
                <filter string="My Team Leaves" name="my_team_leaves" domain="[('employee_id.parent_id.user_id', '=', uid)]" groups="hr_holidays.group_hr_holidays_manager" help="Leaves of Your Team Member"/>
                <separator/>
                <filter name="year" string="Current Year"
                    domain="[('holiday_status_id.active', '=', True)]" help="Active Allocations"/>
                <separator/>
                <filter string="My Allocations" name="my_leaves" domain="[('employee_id.user_id', '=', uid)]"/>
                <separator/>
                <field name="employee_id"/>
                <field name="department_id"/>
                <field name="holiday_status_id"/>
                <separator/>
                <filter string="Late Activities" name="activities_overdue"
                    domain="[('activity_ids.date_deadline', '&lt;', context_today().strftime('%Y-%m-%d'))]"
                    help="Show all records which has next action date is before today"/>
                <filter string="Today Activities" name="activities_today"
                    domain="[('activity_ids.date_deadline', '=', context_today().strftime('%Y-%m-%d'))]"/>
                <filter string="Future Activities" name="activities_upcoming_all"
                        domain="[('activity_ids.date_deadline', '&gt;', context_today().strftime('%Y-%m-%d'))
                        ]"/>
                <group expand="0" string="Group By">
                    <filter name="group_name" string="Description" context="{'group_by':'name'}"/>
                    <filter name="group_employee" string="Employee" context="{'group_by':'employee_id'}"/>
                    <filter name="group_category" string="Category" context="{'group_by':'category_id'}"/>
                    <filter name="group_second_approver_id" string="Validator" context="{'group_by':'second_approver_id'}"/>
                    <filter name="group_type" string="Type" context="{'group_by':'holiday_status_id'}"/>
                </group>
            </search>
        </field>
    </record>

    <record id="hr_leave_allocation_view_form" model="ir.ui.view">
        <field name="name">hr.leave.allocation.view.form</field>
        <field name="model">hr.leave.allocation</field>
        <field name="priority">32</field>
        <field name="arch" type="xml">
            <form string="Allocation Request">
                <field name="can_reset" invisible="1"/>
                <field name="can_approve" invisible="1"/>
                <header>
                    <button string="Confirm" name="action_confirm" states="draft" type="object" class="oe_highlight"/>
                    <field name="state" widget="statusbar" statusbar_visible="draft,confirm,validate"/>
                </header>
                <sheet>
                    <div class="oe_title">
                        <h2><field name="display_name"/></h2>
                    </div>
                    <group>
                        <group>
                            <field name="type_request_unit" invisible="1"/>
                            <field name="name" attrs="{'readonly': [('state', 'not in', ('draft', 'confirm'))]}"/>
                            <field name="holiday_status_id" context="{'employee_id':employee_id}"
                                domain="[('valid', '=', True), ('allocation_type', 'in', ['fixed_allocation', 'no'])]"/>

                            <field name="number_of_days" invisible="1"/>
                            <label for="number_of_days" string="Duration"/>
                            <div>
                                <field name="number_of_days_display" class="oe_inline" nolabel="1"
                                    attrs="{'readonly': ['|', ('type_request_unit', '=', 'hour'), ('state', 'not in', ('draft', 'confirm'))], 'invisible': [('type_request_unit', '=', 'hour')]}"/>
                                <field name="number_of_hours_display" class="oe_inline" nolabel="1"
                                    attrs="{'readonly': ['|', ('type_request_unit', '!=', 'hour'), ('state', 'not in', ('draft', 'confirm'))], 'invisible': [('type_request_unit', '!=', 'hour')]}"/>
                                <span class="ml8" attrs="{'invisible': [('type_request_unit', '=', 'hour')]}">Days</span>
                                <span class="ml8" attrs="{'invisible': [('type_request_unit', '!=', 'hour')]}">Hours</span>
                            </div>

                            <field name="accrual" invisible="1"/>
                        </group>
                        <group name="alloc_right_col">
                            <field name="employee_id" invisible="1" groups="hr_holidays.group_hr_holidays_user"/>
                            <field name="department_id" invisible="1"/>
                        </group>
                    </group>
                    <field name="notes" nolabel="1" placeholder="Add a reason..."/>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers"/>
                    <field name="activity_ids" widget="mail_activity"/>
                    <field name="message_ids" widget="mail_thread"/>
                </div>
            </form>
        </field>
    </record>

    <record id="hr_leave_allocation_view_form_manager" model="ir.ui.view">
        <field name="name">hr.leave.allocation.view.form.manager</field>
        <field name="model">hr.leave.allocation</field>
        <field name="inherit_id" ref="hr_holidays.hr_leave_allocation_view_form"/>
        <field name="mode">primary</field>
        <field name="priority">16</field>
        <field name="arch" type="xml">
            <xpath expr="//button[@name='action_confirm']" position="after">
                <button string="Approve" name="action_approve" states="confirm" type="object" groups="hr_holidays.group_hr_holidays_user" class="oe_highlight"
                    attrs="{'invisible': ['|', ('can_approve', '=', False), ('state', '!=', 'confirm')]}"/>
                <button string="Validate" name="action_validate" states="validate1" type="object" groups="hr_holidays.group_hr_holidays_manager" class="oe_highlight"/>
                <button string="Refuse" name="action_refuse" states="confirm,validate,validate1" type="object" groups="hr_holidays.group_hr_holidays_user"
                    attrs="{'invisible': ['|', ('can_approve', '=', False), ('state', 'not in', ('confirm','validate','validate1'))]}"/>
                <button string="Reset to Draft" name="action_draft" type="object"
                        attrs="{'invisible': ['|', ('can_reset', '=', False), ('state', 'not in', ['confirm', 'refuse'])]}"/>
            </xpath>
            <xpath expr="//field[@name='holiday_status_id']" position="attributes">
                <attribute name="domain">[('valid', '=', True)]</attribute>
            </xpath>
            <xpath expr="//field[@name='employee_id']" position="before">
                <field name="holiday_type" string="Mode" groups="hr_holidays.group_hr_holidays_user" context="{'employee_id':employee_id}" />
            </xpath>
            <xpath expr="//field[@name='employee_id']" position="replace">
                <field name="employee_id" groups="hr_holidays.group_hr_holidays_user"
                    attrs="{'required': [('holiday_type', '=', 'employee')], 'invisible': [('holiday_type', '!=', 'employee')]}"/>
            </xpath>
            <xpath expr="//field[@name='employee_id']" position="after">
                <field name="category_id"
                    attrs="{'required': [('holiday_type', '=', 'category')], 'invisible': [('holiday_type', '!=', 'category')]}"/>
            </xpath>
            <xpath expr="//field[@name='department_id']" position="replace">
                <field name="department_id" groups="hr_holidays.group_hr_holidays_user"
                    attrs="{'required': [('holiday_type', '=', 'department')], 'invisible': [('holiday_type', 'not in', ('department', 'category'))]}"/>
            </xpath>
            <xpath expr="//field[@name='department_id']" position="after">
                <field name="mode_company_id" groups="hr_holidays.group_hr_holidays_user"
                    attrs="{'required': [('holiday_type', '=', 'company')], 'invisible': [('holiday_type', '!=', 'company')]}"/>
            </xpath>
            <xpath expr="//field[@name='accrual']" position="attributes">
                <attribute name="invisible">0</attribute>
            </xpath>
            <xpath expr="//field[@name='accrual']" position="after">
                <label for="date_to" string=""
                    attrs="{'invisible': [('accrual', '=', False)]}"/>
                <div attrs="{'invisible': [('accrual', '=', False)]}">
                    <div class="o_row">
                        Run until <field name="date_to" string="Run Until" help="If no value set, runs indefinitely"/>
                    </div>
                    <div class="o_row">
                        <span>Add</span>
                        <field name="number_per_interval" class="ml8"
                            attrs="{'required': [('accrual', '=', True)]}"/>
                        <field name="unit_per_interval"
                            attrs="{'required': [('accrual', '=', True)]}"/>
                        <span class="ml8">of leaves every</span>
                        <field name="interval_number" class="ml8"
                            attrs="{'required': [('accrual', '=', True)]}"/>
                        <field name="interval_unit"
                            attrs="{'required': [('accrual', '=', True)]}"/>
                    </div>
                </div>
            </xpath>
        </field>
    </record>

    <record id="hr_leave_allocation_view_tree" model="ir.ui.view">
        <field name="name">hr.leave.allocation.view.tree</field>
        <field name="model">hr.leave.allocation</field>
        <field name="priority">16</field>
        <field name="arch" type="xml">
            <tree decoration-danger="state == 'refuse'" decoration-info="state == 'draft'" string="Allocation Requests"
                   decoration-bf="message_needaction == True">
                <field name="employee_id"/>
                <field name="department_id" invisible="1"/>
                <field name="holiday_status_id"/>
                <field name="name"/>
                <field name="duration_display"/>
                <field name="message_needaction" invisible="1"/>
                <field name="state"/>
                <button string="Approve" name="action_approve" type="object"
                    icon="fa-check text-success"
                    states="confirm"
                    groups="hr_holidays.group_hr_holidays_user"/>
                <button string="Validate" name="action_validate" type="object"
                    icon="fa-check text-success"
                    states="validate1"
                    groups="hr_holidays.group_hr_holidays_manager"/>
                <button string="Refuse" name="action_refuse" type="object"
                    icon="fa-ban text-danger"
                    states="confirm,validate,validate1"
                    groups="hr_holidays.group_hr_holidays_manager"/>
            </tree>
        </field>
    </record>

    <record id="hr_leave_allocation_view_tree_my" model="ir.ui.view">
        <field name="name">hr.leave.allocation.view.tree.my</field>
        <field name="model">hr.leave.allocation</field>
        <field name="inherit_id" ref="hr_leave_allocation_view_tree"/>
        <field name="mode">primary</field>
        <field name="priority">32</field>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='employee_id']" position="attributes">
                <attribute name="invisible">1</attribute>
            </xpath>
            <xpath expr="//button[@name='action_approve']" position="attributes">
                <attribute name="invisible">1</attribute>
            </xpath>
            <xpath expr="//button[@name='action_validate']" position="attributes">
                <attribute name="invisible">1</attribute>
            </xpath>
            <xpath expr="//button[@name='action_refuse']" position="attributes">
                <attribute name="invisible">1</attribute>
            </xpath>
        </field>
    </record>

    <record id="hr_leave_allocation_view_kanban" model="ir.ui.view">
        <field name="name">hr.leave.allocation.view.kanban</field>
        <field name="model">hr.leave.allocation</field>
        <field name="arch" type="xml">
            <kanban class="o_kanban_mobile" create="0">
                <field name="employee_id"/>
                <field name="date_from"/>
                <field name="date_to"/>
                <field name="name"/>
                <field name="number_of_days"/>
                <field name="can_approve"/>
                <templates>
                    <t t-name="kanban-box">
                        <div class="oe_kanban_global_click container">
                            <div class="row no-gutters">
                                <div class="col-2">
                                    <img t-att-src="kanban_image('hr.employee', 'image_small', record.employee_id.raw_value)"
                                        t-att-title="record.employee_id.value"
                                        t-att-alt="record.employee_id.value"
                                        width="40" height="40"
                                        class="oe_kanban_avatar float-left mr4 col-md-"/>
                                </div>
                                <div class="col-10">
                                    <span class="badge badge-pill float-right mt4 mr16"><t t-esc="record.number_of_days.value"/> days</span>
                                    <strong class="o_kanban_record_title"><t t-esc="record.employee_id.value"/></strong>
                                    <div class="text-muted o_kanban_record_subtitle">
                                        <t t-esc="record.name.value"/>
                                    </div>
                                    <div class="o_dropdown_kanban dropdown" groups="base.group_user">
                                        <a role="button" class="dropdown-toggle o-no-caret btn" data-toggle="dropdown" href="#" aria-label="Dropdown menu" title="Dropdown menu">
                                            <span class="fa fa-ellipsis-v"/>
                                        </a>
                                        <div class="dropdown-menu" role="menu">
                                            <a t-if="widget.editable" role="menuitem" type="edit" class="dropdown-item">Edit Allocation</a>
                                            <a t-if="widget.deletable" role="menuitem" type="delete" class="dropdown-item">Delete</a>
                                            <a t-if="record.can_approve.value" name="action_approve" type="object"
                                                role="menuitem" class="dropdown-item">Approve</a>
                                            <a t-if="record.can_approve.value" name="action_refuse" type="object"
                                                role="menuitem" class="dropdown-item">Refuse</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
     </record>

    <record id="hr_leave_allocation_action_my" model="ir.actions.act_window">
        <field name="name">My Allocations</field>
        <field name="res_model">hr.leave.allocation</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,kanban,form,activity</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create a new leave allocation request
            </p>
        </field>
        <field name="context">{}</field>
        <field name="domain">[('employee_id.user_id', '=', uid)]</field>
    </record>
    <record id="hr_leave_allocation_action_my_view_tree" model="ir.actions.act_window.view">
        <field name="sequence">1</field>
        <field name="view_mode">tree</field>
        <field name="act_window_id" ref="hr_leave_allocation_action_my"/>
        <field name="view_id" ref="hr_leave_allocation_view_tree_my"/>
    </record>
    <record id="hr_leave_allocation_action_my_view_form" model="ir.actions.act_window.view">
        <field name="sequence">2</field>
        <field name="view_mode">form</field>
        <field name="act_window_id" ref="hr_leave_allocation_action_my"/>
        <field name="view_id" ref="hr_leave_allocation_view_form"/>
    </record>

    <record id="hr_leave_allocation_action_all" model="ir.actions.act_window">
        <field name="name">All Allocations</field>
        <field name="res_model">hr.leave.allocation</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,kanban,form,activity</field>
        <field name="context">{}</field>
        <field name="domain">[]</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create a new leave allocation request
            </p>
        </field>
    </record>

    <record id="hr_leave_allocation_action_approve_department" model="ir.actions.act_window">
        <field name="name">Department Allocation to Approve</field>
        <field name="res_model">hr.leave.allocation</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form,kanban,activity</field>
        <field name="context">{'search_default_department':1, 'search_default_approve':1}</field>
        <field name="domain">[]</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create a new leave allocation
            </p>
        </field>
    </record>

    <menuitem
        id="menu_open_allocation"
        name="Allocations Requests"
        parent="menu_hr_holidays_my_leaves"
        action="hr_leave_allocation_action_my"
        sequence="6"/>

    <menuitem
        id="hr_holidays_menu_manager_approve_allocations"
        name="Allocations"
        parent="hr_holidays_menu_manager_approve"
        groups="hr_holidays.group_hr_holidays_manager,hr_holidays.group_hr_holidays_user"
        action="hr_leave_allocation_action_approve_department"
        sequence="2"/>
    <menuitem
        id="hr_holidays_menu_manager_all_allocations"
        name="Allocations"
        parent="hr_holidays_menu_manager_all"
        groups="hr_holidays.group_hr_holidays_manager,hr_holidays.group_hr_holidays_user"
        action="hr_leave_allocation_action_all"
        sequence="2"/>

</odoo>
