<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <record id="planning_slot_report_view_pivot" model="ir.ui.view">
         <field name="name">planning.slot.report.pivot</field>
         <field name="model">planning.slot.report.analysis</field>
         <field name="arch" type="xml">
             <pivot string="Planning Analysis">
                <field name="entry_date" interval="month" type="col"/>
                <field name="employee_id" type="row"/>
                <field name="number_hours" type="measure"/>
             </pivot>
         </field>
    </record>

    <record id="planning_slot_report_view_graph" model="ir.ui.view">
        <field name="name">planning.slot.report.graph</field>
        <field name="model">planning.slot.report.analysis</field>
        <field name="arch" type="xml">
            <graph string="Planning Analysis" type="bar">
                <field name="entry_date" type="row"/>
                <field name="number_hours" type="measure"/>
            </graph>
        </field>
    </record>

    <record id="planning_slot_report_view_search" model="ir.ui.view">
        <field name="name">planning.slot.report.search</field>
        <field name="model">planning.slot.report.analysis</field>
        <field name="arch" type="xml">
            <search string="Planning Analysis">
                <field name="employee_id" filter_domain="[('employee_id', 'ilike', self)]"/>
                <field name="role_id" filter_domain="[('role_id', 'ilike', self)]"/>
                <field name="entry_date"/>
                <filter string="Date" name="year" date="entry_date"/>
                <separator/>
                <group expand="1" string="Group By">
                    <filter string="Employee" name="resource_employee" context="{'group_by':'employee_id'}"/>
                    <filter string="Role" name="resource_role" context="{'group_by':'role_id'}"/>
                    <filter string="Company" name="resource_company" context="{'group_by':'company_id'}"
                      groups="base.group_multi_company"/>
                    <separator/>
                    <filter string="Date" name="date_month" context="{'group_by':'entry_date:month'}"/>
                </group>
            </search>
        </field>
    </record>

    <record id="planning_action_analysis" model="ir.actions.act_window">
        <field name="name">Shifts Analysis</field>
        <field name="res_model">planning.slot.report.analysis</field>
        <field name="view_mode">pivot,graph</field>
    </record>

    <!-- Filter for graph view -->
    <record id="planning_filter_by_employee" model="ir.filters">
        <field name="name">Hours per Employee</field>
        <field name="model_id">planning.slot.report.analysis</field>
        <field name="user_id" eval="False"/>
        <field name="is_default" eval="True"/>
        <field name="context">{
            'pivot_measures': ['number_hours'],
            'pivot_column_groupby': ['entry_date:month'],
            'pivot_row_groupby': ['employee_id'],
            'graph_measures': ['number_hours'],
            'graph_column_groupby': ['entry_date:month'],
            'graph_row_groupby': ['employee_id']
        }</field>
        <field name="action_id" ref="planning_action_analysis"/>
    </record>

</odoo>
