<?xml version="1.0" ?>
<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"
                            default="context.get('report', False)"/> 
                        <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;=', time.strftime('%%Y-%%m-%%d')), ('date_from','&gt;',(datetime.date.today()-datetime.timedelta(days=30)).strftime('%%Y-%%m-%%d'))]"/>
                        <separator orientation="vertical"/>
                        <field name="employee_id"/>
                        <field name="department_id" widget="selection">
                            <filter icon="terp-personal+" help="My Department Holidays"
                                domain="[('department_id.manager_id','=',uid)]" />
                        </field>
                        <field name="holiday_status_id" widget="selection"/>
                    </group>
                    <newline/>
                    <group expand="0" string="Extended options...">
                        <field name="date_from"/>
                        <field name="date_to"/>
                    </group>
                    <newline />
                    <group expand="0" string="Group By...">
                        <filter string="Employee" icon="terp-personal" domain="[]" context="{'group_by':'employee_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 string="Type" icon="terp-stock_symbol-selection" domain="[]" context="{'group_by':'holiday_status_id'}"
                            default="context.get('report', False)"/>
                        <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" />
                    <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"/>
                            <field name="date_from" on_change="onchange_date_from(date_to, date_from)" required="1"/>
                            <field name="date_to" on_change="onchange_date_to(date_from, date_to)" 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">
                                <button string="Confirm" name="confirm" states="draft" type="workflow" icon="gtk-yes" groups="base.group_hr_user,base.group_hr_manager"/>
                                <button string="Approve" name="validate" states="confirm" type="workflow" icon="gtk-apply" groups="base.group_hr_manager"/>
                                <button string="Approved" name="second_validate" states="validate1" type="workflow" icon="gtk-apply" groups="base.group_hr_manager"/>
                                <button string="Refuse" name="refuse" states="confirm,validate1" type="workflow" icon="gtk-no" groups="base.group_hr_manager"/>
                                <button string="Cancel" name="cancel" states="validate,refuse" type="workflow" icon="gtk-cancel" groups="base.group_hr_manager"/>
                                <button string="Set to Draft" name="set_to_draft" states="cancel" type="object" icon="gtk-convert" groups="base.group_hr_manager"/>
                            </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 Type"/>
                        <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"/>                    
                        <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">
                            <button string="Confirm" name="confirm" states="draft" type="workflow" icon="gtk-yes" groups="base.group_hr_user,base.group_hr_manager"/>
                            <button string="Approve" name="validate" states="confirm" type="workflow" icon="gtk-apply" groups="base.group_hr_manager"/>
                            <button string="Approved" name="second_validate" states="validate1" type="workflow" icon="gtk-apply" groups="base.group_hr_manager"/>
                            <button string="Refuse" name="refuse" states="confirm,validate1" type="workflow" icon="gtk-no" groups="base.group_hr_manager"/>
                            <button string="Cancel" name="cancel" states="validate,refuse" type="workflow" icon="gtk-cancel" groups="base.group_hr_manager"/>
                            <button string="Set to Draft" name="set_to_draft" states="cancel" type="object" icon="gtk-convert" groups="base.group_hr_manager"/>
                        </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');gray:state in ('cancel') " string="Leaves" >
                    <field name="employee_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="Confirm" name="confirm" states="draft" type="workflow" icon="gtk-yes" groups="base.group_hr_user,base.group_hr_manager"/>
                    <button string="Approve" name="validate" states="confirm" type="workflow" icon="gtk-apply" groups="base.group_hr_manager"/>
                    <button string="Approved" name="second_validate" states="validate1" type="workflow" icon="gtk-apply" groups="base.group_hr_manager"/>
                    <button string="Refuse" name="refuse" states="confirm,validate1" type="workflow" icon="gtk-no" groups="base.group_hr_manager"/>
                    <button string="Cancel" name="cancel" states="validate,refuse" type="workflow" icon="gtk-cancel" groups="base.group_hr_manager"/>
                    <button string="Set to Draft" name="set_to_draft" states="cancel" type="object" icon="gtk-convert" groups="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_to(date_from, date_to)" 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" type="workflow" icon="gtk-no"/>
                                <button string="Cancel" name="cancel" states="validate,refuse,validate1" type="workflow" icon="gtk-cancel"/>
                                <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.reprot_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');gray:state in ('cancel')" 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" groups="base.group_hr_user,base.group_hr_manager"/>
                    <button string="Approve" name="validate" states="confirm" type="workflow" icon="gtk-apply" groups="base.group_hr_manager"/>
                    <button string="Refuse" name="refuse" states="confirm" type="workflow" icon="gtk-no" groups="base.group_hr_manager"/>
                    <button string="Cancel" name="cancel" states="validate,refuse,validate1" type="workflow" icon="gtk-cancel" groups="base.group_hr_manager"/>
                    <button string="Set to Draft" name="set_to_draft" states="cancel" type="object" icon="gtk-convert" groups="base.group_hr_manager"/>
                </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');gray:state in ('cancel')">
                    <field name="employee_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="Confirm" name="confirm" states="draft" type="workflow" icon="gtk-yes" groups="base.group_hr_user,base.group_hr_manager"/>
                    <button string="Approve" name="validate" states="confirm" type="workflow" icon="gtk-apply" groups="base.group_hr_manager"/>
                    <button string="Refuse" name="refuse" states="confirm" type="workflow" icon="gtk-no" groups="base.group_hr_manager"/>
                    <button string="Cancel" name="cancel" states="validate,refuse,validate1" type="workflow" icon="gtk-cancel" groups="base.group_hr_manager"/>
                    <button string="Set to Draft" name="set_to_draft" states="cancel" type="object" icon="gtk-convert" groups="base.group_hr_manager"/>
                </tree>
            </field>
        </record>

        <!-- My leave dashboard -->
        <menuitem
            name="Holidays"
            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="domain">[('type','=','remove')]</field>
            <field name="search_view_id" ref="view_hr_holidays_filter"/>
            <field name="help">Leaves 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_user_id':uid,'type':'add'}</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="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">{'allocation_type':'company', 'report':True}</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 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">
                    <field colspan="4" name="name" />
                    <field name="limit"/>
                    <field name="active"/>
                    <field name="categ_id" widget="selection"/>
                    <field name="color_name"/>
                    <field name="double_validation" />
                </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="remaining_leaves"/>
                    <field name="limit" />
                </tree>
            </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>
        </record>

        <menuitem sequence="3" id="hr.menu_open_view_attendance_reason_config" parent="hr.menu_hr_configuration" name="Holidays" groups="base.group_system"/>
        <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="Holidays"
            domain="[('employee_id', '=', active_id), ('type','=','remove')]"
            res_model="hr.holidays"
            src_model="hr.employee"
            view_id ="eval('edit_holiday_new')"
            id="act_hr_employee_holiday_request"/>

    </data>
</openerp>
