<openerp>
    <data>

        <!-- Graph report -->
        <record id="view_evaluation_report_graph" model="ir.ui.view">
                <field name="name">hr.holidays.graph</field>
                <field name="model">hr.holidays</field>
                <field name="arch" type="xml">
                <graph string="Appraisal Analysis" type="pivot" stacked="True">
                    <field name="employee_id" type="row"/>
                    <field name="holiday_status_id" type="row"/>
                    <field name="date_from" type="col"/>
                    <field name="number_of_days" type="measure"/>
                 </graph>
             </field>
        </record>

        <record id="view_hr_holidays_filter" model="ir.ui.view">
            <field name="name">hr.holidays.filter</field>
            <field name="model">hr.holidays</field>
            <field name="arch" type="xml">
                <search string="Search Leave">
                    <field name="name"/>
                    <separator/>
                    <filter domain="[('state','=','draft')]" string="To Confirm"/>
                    <filter domain="[('state','in',('confirm','validate1'))]" string="To Approve" name="approve"/>
                    <filter domain="[('state','=','validate')]" string="Validated" name="validated"/>
                    <separator/>
                    <filter name="year" string="Year" domain="[('holiday_status_id.active','=',True)]" help="Filters only on allocations and requests that belong to an holiday type that is 'active' (active field is True)"/>
                    <separator/>
                    <filter string="My Requests" name="my_leaves" domain="[('employee_id.user_id','=', uid)]" help="My Leave Requests"/>
                    <separator/>
                    <filter string="My Department Leaves" help="My Department Leaves" domain="[('department_id.manager_id','=',uid)]"/>
                    <field name="employee_id"/>
                    <field name="department_id"/>
                    <field name="holiday_status_id"/>
                    <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 string="Manager" context="{'group_by':'manager_id'}"/>
                        <filter name="group_type" string="Type" context="{'group_by':'holiday_status_id'}"/>
                        <separator/>
                        <filter name="group_date_from" string="Start Month" context="{'group_by':'date_from:month'}"/>
                    </group>
                </search>
            </field>
        </record>

        <!-- Holidays: Leave Request -->

        <record id="view_holiday_new_calendar" model="ir.ui.view">
            <field name="name">Leave Request</field>
            <field name="model">hr.holidays</field>
            <field name="arch" type="xml">
                <calendar string="Leave Request" color="employee_id"
                          date_start="date_from" date_stop="date_to"
                          quick_add="False" avatar_model="hr.employee">
                    <field name="employee_id"/>
                    <field name="holiday_status_id"/>
                </calendar>
            </field>
        </record>

        <!-- Holidays: Allocation Request -->
        <record model="ir.ui.view" id="edit_holiday_new">
            <field name="name">Leave Request</field>
            <field name="model">hr.holidays</field>
            <field name="arch" type="xml">
                <form string="Leave Request">
                <field name="can_reset" invisible="1"/>
                <field name="type" invisible="1"/>
                <header>
                    <button string="Confirm" name="confirm" states="draft" type="workflow" class="oe_highlight"/>
                    <button string="Approve" name="validate" states="confirm" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
                    <button string="Validate" name="second_validate" states="validate1" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
                    <button string="Refuse" name="refuse" states="confirm,validate,validate1" type="workflow" groups="base.group_hr_user"/>
                    <button string="Reset to Draft" name="reset" type="workflow"
                            attrs="{'invisible': ['|', ('can_reset', '=', False), ('state', 'not in', ['confirm', 'refuse'])]}"/>
                    <field name="state" widget="statusbar" statusbar_visible="draft,confirm,validate" statusbar_colors='{"confirm":"blue","validate1":"blue","refuse":"red"}'/>
                </header>
                <sheet>
                    <group>
                        <group>
                            <field name="name" attrs="{'readonly':[('state','!=','draft'),('state','!=','confirm')], 'required': [('type', '=', 'add')]}"/>
                            <field name="holiday_status_id" context="{'employee_id':employee_id}"/>
                                <label for="number_of_days_temp" string="Duration"/>
                            <div>
                                <group col="3" attrs="{'invisible': [('type', '=', 'add')]}">
                                    <field name="date_from" nolabel="1" on_change="onchange_date_from(date_to, date_from)" attrs="{'required':[('type', '=', 'remove')]}" class="oe_inline"/><label string="-" class="oe_inline"/>
                                    <field name="date_to" nolabel="1" on_change="onchange_date_to(date_to, date_from)"  attrs="{'required':[('type', '=', 'remove')]}" class="oe_inline"/>
                                </group>
                                <div>
                                    <field name="number_of_days_temp" class="oe_inline"/> days
                                </div>
                            </div>
                        </group>
                        <group>
                            <field name="holiday_type" on_change="onchange_type(holiday_type)" attrs="{'readonly':[('type', '=', 'remove'),('state','!=','draft')]}" string="Mode" groups="base.group_hr_user" context="{'employee_id':employee_id}" />
                            <field name="employee_id" attrs="{'required':[('holiday_type','=','employee')],'invisible':[('holiday_type','=','category')]}" on_change="onchange_employee(employee_id)" groups="base.group_hr_user"/>
                            <field name="category_id" attrs="{'required':[('holiday_type','=','category')], 'readonly': [('type', '=', 'remove'),('state','!=','draft'), ('state','!=','confirm')], 'invisible':[('holiday_type','=','employee')]}"/>
                            <field name="department_id" attrs="{'readonly':['|', ('type','=','add'),('holiday_type','=','category')],'invisible':[('holiday_type','=','category')]}" groups="base.group_hr_user"/>
                        </group>
                    </group>
                    <field name="notes" nolabel="1" colspan="4" placeholder="Add a reason..." attrs="{'invisible': [('type', '=', 'remove')]}"/>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers"/>
                    <field name="message_ids" widget="mail_thread"/>
                </div>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="view_holiday_allocation_tree">
            <field name="name">hr.holidays.allocation.tree</field>
            <field name="model">hr.holidays</field>
            <field name="arch" type="xml">
                <tree colors="red:state == 'refuse';blue:state == 'draft';black:state in ('confirm','validate','validate1')" string="Allocation Requests">
                    <field name="employee_id"/>
                    <field name="holiday_type"/>
                    <field name="category_id"/>
                    <field name="department_id" invisible="1"/>
                    <field name="holiday_status_id"/>
                    <field name="name"/>
                    <field name="number_of_days" string="Allocated Days" sum="Remaining Days"/>
                    <field name="manager_id" invisible="1"/>
                    <field name="user_id" invisible="1"/>
                    <field name="date_from" invisible="1"/>
                    <!--field name="type"/-->
                    <field name="state"/>
                </tree>
            </field>
        </record>

        <!-- Holidays: Leaves Management -->
        <record model="ir.ui.view" id="allocation_company_new">
            <field name="name">Leaves Management</field>
            <field name="model">hr.holidays</field>
            <field name="arch" type="xml">
                <form string="Leaves Management">
                    <header>
                        <button string="Submit to Manager" name="confirm" states="draft" type="workflow" icon="gtk-yes"/>
                        <button string="Approve" name="validate" states="confirm" type="workflow" icon="gtk-apply"/>
                        <button string="Refuse" name="refuse" states="confirm,validate,draft" type="workflow" icon="gtk-no"/>
                        <button string="Reset to Draft" name="reset" states="confirm" type="workflow" groups="base.group_hr_manager"/>
                        <field name="state"/>
                    </header>
                    <group col="4">
                        <field name="holiday_status_id"/>
                        <field name="type"/>
                        <field name="date_from" on_change="onchange_date_from(date_to, date_from)" attrs="{'readonly':[('type','=','add')], 'required':[('type','=','remove')]}"/>
                        <field name="date_to" on_change="onchange_date_from(date_to, date_from)" attrs="{'readonly':[('type','=','add')], 'required':[('type','=','remove')]}"/>
                        <field name="number_of_days_temp"/>
                        <field name="manager_id"/>
                    </group>
                    <field name="name" placeholder="Add a reason..."/>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="view_holiday_simple">
            <field name="name">hr.holidays.report_tree</field>
            <field name="model">hr.holidays</field>
            <field name="priority">20</field>
            <field name="arch" type="xml">
                <tree colors="red:state == 'refuse';blue:state == ' draft';black:state in ('confirm','validate','validate1')" string="Leaves Summary">
                    <field name="employee_id"/>
                    <field name="category_id" invisible="1"/>
                    <field name="department_id" invisible="1"/>
                    <field name="type"/>
                    <field name="name"/>
                    <field name="number_of_days" string="Number of Days" sum="Remaining Days"/>
                    <field name="date_from"/>
                    <field name="date_to"/>
                    <field name="holiday_status_id"/>
                    <field name="manager_id" invisible="1"/>
                    <field name="user_id" invisible="1"/>
                    <field name="state"/>
                </tree>
            </field>
        </record>

        <record model="ir.ui.view" id="view_holiday">
            <field name="name">hr.holidays.tree</field>
            <field name="model">hr.holidays</field>
            <field name="arch" type="xml">
                <tree colors="red:state == 'refuse';blue:state == ' draft';black:state in ('confirm','validate','validate1')" string="Leave Requests">
                    <field name="employee_id"/>
                    <field name="holiday_type" string="Mode" groups="base.group_no_one"/>
                    <field name="holiday_status_id"/>
                    <field name="name"/>
                    <field name="date_from"/>
                    <field name="date_to"/>
                    <field name="number_of_days" string="Number of Days" sum="Remaining Days"/>
                    <field name="state"/>
                    <field name="category_id" invisible="1"/>
                    <field name="department_id" invisible="not context.get('set_visible',False)"/>
                    <field name="manager_id" invisible="1"/>
                    <field name="user_id" invisible="1"/>
                </tree>
            </field>
        </record>

        <menuitem name="Leaves" parent="hr.menu_hr_root" id="menu_open_ask_holidays" sequence="20"/>

        <record model="ir.actions.act_window" id="open_ask_holidays">
            <field name="name">Leave Request</field>
            <field name="res_model">hr.holidays</field>
            <field name="view_type">form</field>
            <field name="view_id" ref="edit_holiday_new"/>
            <field name="context">{'default_type': 'remove', 'search_default_my_leaves':1}</field>
            <field name="domain">[('type','=','remove')]</field>
            <field name="search_view_id" ref="view_hr_holidays_filter"/>
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                Click to create a new leave request.
              </p><p>
                Once you have recorded your leave request, it will be sent
                to a manager for validation. Be sure to set the right leave
                type (recuperation, legal holidays, sickness) and the exact
                number of open days related to your leave.
              </p>
            </field>
        </record>

        <record model="ir.actions.act_window.view" id="action_open_ask_holidays_tree">
            <field name="sequence" eval="2"/>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="view_holiday"/>
            <field name="act_window_id" ref="open_ask_holidays"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_open_ask_holidays_form">
            <field name="sequence" eval="3"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="edit_holiday_new"/>
            <field name="act_window_id" ref="open_ask_holidays"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_open_ask_holidays_calendar">
            <field name="sequence" eval="1"/>
            <field name="view_mode">calendar</field>
            <field name="view_id" ref="view_holiday_new_calendar"/>
            <field name="act_window_id" ref="open_ask_holidays"/>
        </record>

        <menuitem parent="menu_open_ask_holidays" id="menu_open_ask_holidays_new" action="open_ask_holidays"/>

        <record model="ir.actions.act_window" id="request_approve_holidays">
            <field name="name">Requests to Approve</field>
            <field name="res_model">hr.holidays</field>
            <field name="view_type">form</field>
            <field name="context">{'default_type': 'remove', 'search_default_approve':1}</field>
            <field name="domain">[('type','=','remove')]</field>
            <field name="view_id" ref="edit_holiday_new"/>
            <field name="search_view_id" ref="view_hr_holidays_filter"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_request_approve_holidays_tree">
            <field name="sequence" eval="1"/>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="view_holiday"/>
            <field name="act_window_id" ref="request_approve_holidays"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_request_approve_holidays_form">
            <field name="sequence" eval="2"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="edit_holiday_new"/>
            <field name="act_window_id" ref="request_approve_holidays"/>
        </record>

        <menuitem name="Leave Requests to Approve" parent="menu_open_ask_holidays" id="menu_request_approve_holidays" action="request_approve_holidays" groups="base.group_hr_user"/>

        <record model="ir.actions.act_window" id="open_allocation_holidays">
            <field name="name">Allocation Requests</field>
            <field name="res_model">hr.holidays</field>
            <field name="view_type">form</field>
            <field name="context">{'default_type':'add', 'search_default_my_leaves':1}</field>
            <field name="domain">[('type','=','add')]</field>
            <field name="view_id" ref="edit_holiday_new"/>
            <field name="search_view_id" ref="view_hr_holidays_filter"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_open_allocation_holidays_tree">
            <field name="sequence" eval="1"/>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="view_holiday_allocation_tree"/>
            <field name="act_window_id" ref="open_allocation_holidays"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_open_allocation_holidays_form">
            <field name="sequence" eval="2"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="edit_holiday_new"/>
            <field name="act_window_id" ref="open_allocation_holidays"/>
        </record>

        <menuitem parent="menu_open_ask_holidays" id="menu_open_allocation_holidays" action="open_allocation_holidays"/>

        <record model="ir.actions.act_window" id="request_approve_allocation">
            <field name="name">Allocation Requests to Approve</field>
            <field name="res_model">hr.holidays</field>
            <field name="view_type">form</field>
            <field name="context">{'default_type': 'add', 'search_default_approve':1}</field>
            <field name="domain">[('type','=','add')]</field>
            <field name="view_id" ref="edit_holiday_new"/>
            <field name="search_view_id" ref="view_hr_holidays_filter"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_request_approve_allocation_tree">
            <field name="sequence" eval="1"/>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="view_holiday_allocation_tree"/>
            <field name="act_window_id" ref="request_approve_allocation"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_request_approve_allocation_form">
            <field name="sequence" eval="2"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="edit_holiday_new"/>
            <field name="act_window_id" ref="request_approve_allocation"/>
        </record>

        <menuitem parent="menu_open_ask_holidays" id="menu_request_approve_allocation" action="request_approve_allocation" groups="base.group_hr_manager"/>

        <record model="ir.actions.act_window" id="open_company_allocation">
            <field name="name">Leaves Summary</field>
            <field name="res_model">hr.holidays</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" eval="view_holiday_simple"/>
            <field name="context">{'search_default_group_type': 1}</field>
            <field name="domain">[('holiday_type','=','employee'), ('state', '!=', 'refuse')]</field>
            <field name="search_view_id" ref="view_hr_holidays_filter"/>
        </record>

        <menuitem name="Leaves Summary" parent="menu_open_ask_holidays" id="menu_open_company_allocation" action="open_company_allocation" sequence="40"/>

        <!-- Holidays status -->
        <record id="view_holidays_status_filter" model="ir.ui.view">
            <field name="name">hr.holidays.status.filter</field>
            <field name="model">hr.holidays.status</field>
            <field name="arch" type="xml">
                <search string="Search Leave Type">
                    <field name="name" string="Leave Types"/>
                    <field name="categ_id"/>
                </search>
            </field>
        </record>

        <record model="ir.ui.view" id="edit_holiday_status_form">
            <field name="name">hr.holidays.status.form</field>
            <field name="model">hr.holidays.status</field>
            <field name="arch" type="xml">
                <form string="Leave Type">
                <sheet string="Leave Type">
                    <group col="4">
                        <field name="name"/>
                        <field name="categ_id"/>
                    </group>
                    <notebook>
                      <page string="Details">
                          <group>
                              <group name="selection" string="Validation">
                                  <field name="double_validation"/>
                                  <field name="limit"/>
                              </group>
                              <group name="second" string="Misc">
                                  <field name="color_name"/>
                                  <field name="active"/>
                              </group>
                          </group>
                      </page>
                    </notebook>
                </sheet>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="view_holiday_status_tree">
            <field name="name">hr.holidays.status.tree</field>
            <field name="model">hr.holidays.status</field>
            <field name="arch" type="xml">
                <tree string="Leave Type">
                    <field name="name"/>
                    <field name="max_leaves"/>
                    <field name="leaves_taken"/>
                    <field name="remaining_leaves"/>
                </tree>
            </field>
        </record>

        <record model="ir.ui.view" id="view_holiday_status_normal_tree">
            <field name="name">hr.holidays.status.normal.tree</field>
            <field name="model">hr.holidays.status</field>
            <field name="priority">35</field>
            <field name="arch" type="xml">
                <tree string="Leave Type">
                    <field name="name"/>
                    <field name="limit"/>
                </tree>
            </field>
        </record>

        <record id="view_hr_holidays_status_search" model="ir.ui.view">
            <field name="name">hr.holidays.status.search</field>
            <field name="model">hr.holidays.status</field>
            <field name="arch" type="xml">
                <search string="Leave Type">
                    <field name="name" string="Leave Types"/>
                    <field name="categ_id"/>
                </search>
            </field>
        </record>

        <record id="open_view_holiday_status" model="ir.actions.act_window">
            <field name="name">Leave Types</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">hr.holidays.status</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" eval="view_holiday_status_normal_tree"/>
            <field name="search_view_id" ref="view_hr_holidays_status_search"/>
        </record>

        <menuitem sequence="3" id="hr.menu_open_view_attendance_reason_config" parent="hr.menu_hr_configuration" name="Leaves"/>
        <menuitem name="Leaves Types" action="open_view_holiday_status" id="menu_open_view_holiday_status" parent="hr.menu_hr_configuration" sequence="10"/>

        <!-- Holiday on resource leave -->
        <record id="resource_calendar_leave_form_inherit" model="ir.ui.view">
            <field name="name">resource.calendar.leaves.form.inherit</field>
            <field name="model">resource.calendar.leaves</field>
            <field name="inherit_id" ref="resource.resource_calendar_leave_form"/>
            <field name="arch" type="xml">
                <field name="name" position="after">
                    <field name="holiday_id"/>
                </field>
            </field>
        </record>

        <!-- Shortcuts -->
        <record id="act_hr_employee_holiday_request" model="ir.actions.act_window">
            <field name="name">Leaves</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">hr.holidays</field>
            <field name="src_model">hr.employee</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="context">{'search_default_employee_id': [active_id], 'default_employee_id': active_id}</field>
            <field name="domain">[('type','=','remove')]</field>
            <field name="view_id" eval="view_holiday"/>
        </record>

       <!-- Assing leave -->
        <record id="hr_holidays_leaves_assign_tree_view" model="ir.ui.view">
            <field name="name">hr.employee.leave.tree</field>
            <field name="model">hr.employee</field>
            <field name="priority" eval="20"/>
            <field name="arch" type="xml">
                <tree string="Assign Leaves" editable="bottom">
                    <field name="name" string="Employee"/>
                    <field name="remaining_leaves" string="Remaining Legal Leaves"/>
                </tree>
            </field>
        </record>

        <record model="ir.actions.act_window" id="hr_holidays_leaves_assign_legal">
           <field name="name">Allocate Leaves for Employees</field>
           <field name="type">ir.actions.act_window</field>
           <field name="res_model">hr.employee</field>
           <field name="view_type">form</field>
           <field name="view_mode">tree,form</field>
           <field name="view_id" ref="hr_holidays_leaves_assign_tree_view"/>
           <field name="help" type="html">
             <p>
               You can assign remaining Legal Leaves for each employee, Odoo
               will automatically create and validate allocation requests.
             </p>
           </field>
       </record>

        <!-- Hr employee inherit Legal Leaves -->
        <record id="view_employee_form_leave_inherit" model="ir.ui.view">
            <field name="name">hr.employee.leave.form.inherit</field>
            <field name="model">hr.employee</field>
            <field name="inherit_id" ref="hr.view_employee_form"/>
            <field name="arch" type="xml">
                <xpath expr="//group[@name='active_group']" position="before">
                    <group string="Leaves">
                        <label for="remaining_leaves"/>
                        <div>
                            <field name="remaining_leaves" class="oe_inline"/> days
                        </div>
                    </group>
                </xpath>
                <xpath expr="//div[@name='button_box']" position="inside">
                    <button name="%(act_hr_employee_holiday_request)d"
                        type="action"
                        class="oe_stat_button"
                        icon="fa-calendar"
                        groups="base.group_hr_user">
                        <field name="leaves_count" widget="statinfo" string="Leaves"/>
                    </button>
                </xpath>
            </field>
        </record>

        <record model="ir.ui.view" id="hr_kanban_view_employees_kanban">
            <field name="name">HR - Employees Kanban with leave status</field>
            <field name="model">hr.employee</field>
            <field name="inherit_id" ref="hr.hr_kanban_view_employees"/>
            <field name="arch" type="xml">
                <xpath expr="//templates" position="before">
                    <field name="current_leave_id"/>
                    <field name="current_leave_state"/>
                    <field name="leave_date_from"/>
                    <field name="leave_date_to"/>
                </xpath>
                <xpath expr="//div[@class='oe_employee_details']/ul/li[@id='last_login']" position="inside">
                    <span t-if="record.current_leave_id.raw_value" style="font-size: 100%%"
                            t-att-class="record.current_leave_state.raw_value=='validate'?'oe_kanban_button oe_kanban_color_3':'oe_kanban_button oe_kanban_color_2'"
                            t-att-title="record.leave_date_from.raw_value.toString('ddd dS MMM') + ' - ' + record.leave_date_to.raw_value.toString('ddd dS MMM')">
                        <field name="current_leave_id"/>
                    </span>
                </xpath>
            </field>
        </record>

        <act_window
            id="act_hr_leave_request_to_meeting"
            name="Leave Meetings"
            src_model="hr.holidays"
            res_model="calendar.event"
            view_mode="tree,form,calendar,gantt"
            view_type="form"/>

    </data>
</openerp>
