<openerp>
    <data>

        <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="type">search</field>
            <field name="arch" type="xml">
                <search string="Search Leave">
                    <group col="8" colspan="4">
                        <filter icon="terp-camera_test" domain="[('state','=','validate')]" string="Validated"/>
                        <separator orientation="vertical"/>
                        <filter icon="terp-check" domain="[('state','=','draft')]" string="To Confirm"/>
                        <filter icon="terp-camera_test" domain="[('state','=','confirm')]" string="To Approve"/>
                        <separator orientation="vertical"/>
                        <filter string="This Month" icon="terp-go-month" name="This Month" domain="[('date_from','&lt;=',(datetime.date.today()+relativedelta(day=31)).strftime('%%Y-%%m-%%d')),('date_from','&gt;=',(datetime.date.today()-relativedelta(day=1)).strftime('%%Y-%%m-%%d'))]"/>
                        <separator orientation="vertical"/>
                        <field name="employee_id">
                            <filter icon="terp-personal" name="my_leaves" domain="[('employee_id.user_id','=', uid)]" help="My Leaves"/>
                        </field>
                        <field name="department_id" widget="selection">
                            <filter icon="terp-personal+" help="My Department Leaves" domain="[('department_id.manager_id','=',uid)]"/>
                        </field>
                        <field name="holiday_status_id" widget="selection"/>
                        <field name="date_from"/>
                        <field name="date_to"/>
                    </group>
                    <newline/>
                    <group expand="0" string="Group By...">
                        <filter name="group_employee" string="Employee" icon="terp-personal" domain="[]" context="{'group_by':'employee_id'}"/>
                        <filter name="group_category" string="Category" icon="terp-stock_symbol-selection" domain="[]" context="{'group_by':'category_id'}"/>
                        <filter string="Manager" icon="terp-personal" domain="[]" context="{'group_by':'manager_id'}"/>
                        <filter string="Department" icon="terp-personal+" domain="[]" context="{'group_by':'department_id','set_visible':True}"/>
                        <separator orientation="vertical"/>
                        <filter name="group_type" string="Type" icon="terp-stock_symbol-selection" domain="[]" context="{'group_by':'holiday_status_id'}"/>
                        <separator orientation="vertical"/>
                        <filter string="State" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/>
                    </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="type">calendar</field>
            <field name="arch" type="xml">
                <calendar string="Leave Request" color="name" date_start="date_from" date_stop="date_to">
                    <field name="holiday_status_id"/>
                </calendar>
            </field>
        </record>

        <record model="ir.ui.view" id="edit_holiday_new">
            <field name="name">Leave Request</field>
            <field name="model">hr.holidays</field>
            <field name="type">form</field>
            <field name="priority">1</field>
            <field name="arch" type="xml">
                <form string="Leave Request">
                    <group col="8" colspan="4">
                    <field name="name" attrs="{'readonly':[('state','!=','draft'),('state','!=','confirm')]}"/>
                    <field name="holiday_type" on_change="onchange_type(holiday_type)" attrs="{'readonly':[('state','!=','draft')]}" width="130" groups="base.group_hr_manager"/>
                    <group attrs="{'invisible':[('holiday_type','=','employee')]}">
                        <field name="category_id" attrs="{'required':[('holiday_type','=','category')], 'readonly':[('state','!=','draft')]}"/>
                        </group>
                        <group attrs="{'invisible':[('holiday_type','=','category')]}">
                        <field name="employee_id" attrs="{'required':[('holiday_type','=','employee')]}"/>
                        </group>
                    </group>
                    <notebook colspan="4">
                        <page string="General">
                            <field name="holiday_status_id" on_change="onchange_sec_id(holiday_status_id)" context="{'employee_id':employee_id}"/>
                            <field name="department_id" attrs="{'readonly':[('holiday_type','=','category')]}"/>
                            <field name="date_from" on_change="onchange_date_from(date_to, date_from)" required="1"/>
                            <field name="date_to" on_change="onchange_date_from(date_to, date_from)" required="1"/>
                            <field name="number_of_days_temp"/>
                            <newline/>
                            <field name="manager_id"/>
                            <field name="manager_id2"/>
                            <separator string="Reasons" colspan="4"/>
                            <field name="notes" nolabel="1" colspan="4"/>
                            <newline/>
                            <field name="state" colspan="2"/>
                            <group colspan="2" col="6">
                                <button string="Refuse" name="refuse" states="confirm,validate1" type="workflow" icon="gtk-no" groups="base.group_hr_user,base.group_hr_manager"/>
                                <button string="Confirm" name="confirm" states="draft" type="workflow" icon="gtk-yes"/>
                                <button string="Approve" name="validate" states="confirm" type="workflow" icon="gtk-apply" groups="base.group_hr_user"/>
                                <button string="Approved" name="second_validate" states="validate1" type="workflow" icon="gtk-apply" groups="base.group_hr_user"/>
                                <button string="Set to Draft" name="set_to_draft" states="refuse,validate,validate1" type="object" icon="gtk-convert" groups="base.group_hr_user"/>
                            </group>
                        </page>
                    </notebook>
                </form>
            </field>
        </record>

        <!-- Holidays: Allocation Request -->
        <record model="ir.ui.view" id="allocation_leave_new">
            <field name="name">Allocation Request</field>
            <field name="model">hr.holidays</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
            <form string="Allocation Request">
                <group col="8" colspan="4">
                    <field name="name"/>
                    <field name="holiday_type" on_change="onchange_type(holiday_type)" attrs="{'readonly':[('state','!=','draft')]}" string="Allocation Category" groups="base.group_hr_manager"/>
                        <group attrs="{'invisible':[('holiday_type','=','category')]}">
                        <field name="employee_id" attrs="{'required':[('holiday_type','=','employee')]}"/>
                        </group>
                        <group attrs="{'invisible':[('holiday_type','=','employee')]}">
                        <field name="category_id" attrs="{'required':[('holiday_type','=','category')], 'readonly':[('state','!=','draft')]}"/>
                        </group>
                </group>
                <notebook colspan="4">
                    <page string="General">
                        <field name="holiday_status_id" on_change="onchange_sec_id(holiday_status_id)" context="{'employee_id':employee_id}"/>
                        <field name="department_id" attrs="{'readonly':[('holiday_type','=','category')]}"/>
                        <field name="number_of_days_temp"/>
                        <newline/>
                        <field name="manager_id"/>
                        <field name="manager_id2"/>
                        <separator string="Reasons" colspan="4"/>
                        <field name="notes" nolabel="1" colspan="4"/>
                        <newline/>
                        <field name="state" colspan="2"/>
                        <group colspan="2" col="6">
                            <button string="Refuse" name="refuse" states="confirm" type="workflow" icon="gtk-no" groups="base.group_hr_user"/>
                            <button string="Confirm" name="confirm" states="draft" type="workflow" icon="gtk-yes"/>
                            <button string="Approve" name="validate" states="confirm" type="workflow" icon="gtk-apply" groups="base.group_hr_user"/>
                            <button string="Approved" name="second_validate" states="validate1" type="workflow" icon="gtk-apply" groups="base.group_hr_user"/>
                            <button string="Set to Draft" name="set_to_draft" states="cancel,validate,validate1,refuse" type="object" icon="gtk-convert" groups="base.group_hr_user"/>
                        </group>
                    </page>
                </notebook>
            </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="type">tree</field>
            <field name="arch" type="xml">
                <tree colors="red:state in ('refuse');blue:state in ('draft');black:state in ('confirm','validate','validate1')" string="Leaves">
                    <field name="holiday_type"/>
                    <field name="employee_id"/>
                    <field name="category_id"/>
                    <field name="department_id" invisible="1"/>
                    <field name="holiday_status_id"/>
                    <field name="name"/>
                    <field name="number_of_days" string="Number of Days" sum="Remaining Days"/>
                    <field name="manager_id" invisible="1"/>
                    <field name="user_id" invisible="1"/>
                    <!--field name="type"/-->
                    <field name="state"/>
                    <button string="Approve" name="validate" states="confirm" type="workflow" icon="gtk-apply" groups="base.group_hr_user,base.group_hr_manager"/>
                    <button string="Approved" name="second_validate" states="validate1" type="workflow" icon="gtk-apply" groups="base.group_hr_user,base.group_hr_manager"/>
                </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="type">form</field>
            <field name="arch" type="xml">
                <form string="Leaves Management">
                    <field name="name"/>
                    <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"/>
                    <notebook colspan="4">
                        <page string="General">
                            <field name="manager_id"/>
                            <field name="notes" colspan="4"/>
                            <newline/>
                            <field name="state" colspan="2"/>
                            <group colspan="2">
                                <button string="Confirm" 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="Set to Draft" name="set_to_draft" states="cancel" type="object" icon="gtk-convert"/>
                            </group>
                        </page>
                    </notebook>
                </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="type">tree</field>
            <field name="priority">20</field>
            <field name="arch" type="xml">
                <tree colors="red:state in ('refuse');blue:state in (' draft');black:state in ('confirm','validate','validate1')" string="Leaves Summary">
                    <field name="employee_id"/>
                    <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"/>
                    <button string="Confirm" name="confirm" states="draft" type="workflow" icon="gtk-yes"/>
                    <button string="Approve" name="validate" states="confirm" type="workflow" icon="gtk-apply" groups="base.group_hr_user"/>
                    <button string="Refuse" name="refuse" states="confirm" type="workflow" icon="gtk-no" groups="base.group_hr_user"/>
                </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="type">tree</field>
            <field name="arch" type="xml">
                <tree colors="red:state in ('refuse');blue:state in (' draft');black:state in ('confirm','validate','validate1')">
                    <field name="holiday_type"/>
                    <field name="employee_id"/>
                    <field name="category_id"/>
                    <field name="department_id" invisible="not context.get('set_visible',False)"/>
                    <field name="holiday_status_id"/>
                    <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="manager_id" invisible="1"/>
                    <field name="user_id" invisible="1"/>
                    <!--field name="type"/-->
                    <field name="state"/>
                    <button string="Approve" name="validate" states="confirm" type="workflow" icon="gtk-apply" groups="base.group_hr_user,base.group_hr_manager"/>
                    <button string="Approved" name="second_validate" states="validate1" type="workflow" icon="gtk-apply" groups="base.group_hr_user,base.group_hr_manager"/>
                </tree>
            </field>
        </record>

        <!-- My leave dashboard -->
        <menuitem name="Leaves" parent="hr.menu_hr_root" id="menu_open_ask_holidays" sequence="5"/>

        <record model="ir.actions.act_window" id="open_ask_holidays">
            <field name="name">Leave Requests</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">{"search_default_department_id": department_id, "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">Leave requests can be recorded by employees and validated by their managers. Once a leave request is validated, it appears automatically in the agenda of the employee. You can define several allowance types (paid holidays, sickness, etc.) and manage allowances per type.</field>
        </record>

        <record model="ir.actions.act_window.view" id="action_open_ask_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="open_ask_holidays"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_open_ask_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_ask_holidays"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_open_ask_holidays_calendar">
            <field name="sequence" eval="3"/>
            <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 name="Leave Requests" parent="menu_open_ask_holidays" id="menu_open_ask_holidays_new" action="open_ask_holidays"/>

        <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">{"search_default_my_leaves": 1,'default_type':'add',"search_default_department_id": department_id}</field>
            <field name="domain">[('type','=','add')]</field>
            <field name="view_id" ref="allocation_leave_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="allocation_leave_new"/>
            <field name="act_window_id" ref="open_allocation_holidays"/>
        </record>

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

        <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_my_leaves': 1, 'search_default_group_type': 1}</field>
            <field name="domain">[('holiday_type','=','employee')]</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="type">search</field>
            <field name="arch" type="xml">
                <search string="Search Leave Type">
                    <field name="name"/>
                    <field name="categ_id" widget="selection"/>
                </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="type">form</field>
            <field name="arch" type="xml">
                <form string="Leave Type">
                    <group colspan="4" col="6">
                        <field name="name"/>
                        <field name="color_name"/>
                        <field name="categ_id" widget="selection" groups="base.group_extended"/>
                    </group>
                    <notebook colspan="4">
                      <page string="Details">
                          <group colspan="2" col="2" name="selection">
                              <separator string="Validation" colspan="2"/>
                              <field name="double_validation"/>
                              <field name="limit"/>
                          </group>
                          <group name="second" colspan="2" col="2">
                              <separator string="Misc" colspan="2"/>
                              <field name="active"/>
                          </group>
                      </page>
                    </notebook>
                </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="type">tree</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"/>
                    <field name="limit"/>
                </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="type">tree</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="type">search</field>
            <field name="arch" type="xml">
                <search string="Leave Type">
                    <field name="name"/>
                    <field name="categ_id" widget="selection"/>
                </search>
            </field>
        </record>
        
        <record id="open_view_holiday_status" model="ir.actions.act_window">
            <field name="name">Leave Type</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="Leave Type" action="open_view_holiday_status" id="menu_open_view_holiday_status" parent="hr.menu_open_view_attendance_reason_config"/>

    <!-- 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="type">form</field>
            <field name="inherit_id" ref="resource.resource_calendar_leave_form"/>
            <field name="arch" type="xml">
                <field name="date_to" position="after">
                    <field name="holiday_id"/>
                </field>
            </field>
        </record>

    <!--  Shortcuts -->
        <act_window name="Leaves" domain="[('type','=','remove')]" context="{'search_default_employee_id': [active_id], 'default_employee_id': active_id}" res_model="hr.holidays" src_model="hr.employee" view_id="view_holiday" id="act_hr_employee_holiday_request"/>
            
       <!--  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="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Assign Leaves" editable="top">
                    <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">Assign Legal Leaves to 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"/>
       </record>

       <record id="hr_holidays_leaves_assign_form_view_todo" model="ir.actions.todo">
           <field name="action_id" ref="hr_holidays_leaves_assign_legal"/>
           <field name="category_id" ref="hr.category_hr_management_config"/>
       </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="type">form</field>
            <field name="inherit_id" ref="hr.view_employee_form"/>
            <field name="arch" type="xml">
                <field name="coach_id" position="after">
                    <field name="remaining_leaves" string="Remaining Legal Leaves"/>
                </field>
            </field>
        </record>

    </data>
</openerp>
