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

    <record id="project_timesheet_forecast_report_view_pivot" model="ir.ui.view">
         <field name="name">timesheet.forecast.report.pivot</field>
         <field name="model">project.timesheet.forecast.report.analysis</field>
         <field name="arch" type="xml">
             <pivot string="Timesheet 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="project_timesheet_forecast_report_view_graph" model="ir.ui.view">
        <field name="name">timesheet.forecast.report.graph</field>
        <field name="model">project.timesheet.forecast.report.analysis</field>
        <field name="arch" type="xml">
            <graph string="Timesheet Planning Analysis" type="bar">
                <field name="entry_date" type="row"/>
                <field name="number_hours" type="measure"/>
            </graph>
        </field>
    </record>

    <record id="project_timesheet_forecast_report_view_search" model="ir.ui.view">
        <field name="name">timesheet.forecast.report.search</field>
        <field name="model">project.timesheet.forecast.report.analysis</field>
        <field name="arch" type="xml">
            <search string="Timesheet Planning Analysis">
                <field name="employee_id" filter_domain="[('employee_id', 'ilike', self)]"/>
                <field name="project_id" filter_domain="[('project_id', 'ilike', self)]"/>
                <field name="task_id" filter_domain="[('task_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="Task" name="resource_task" context="{'group_by':'task_id'}"/>
                    <filter string="Project" name="project_resource" context="{'group_by':'project_id'}"/>
                    <separator/>
                    <filter string="Date" name="date_month" context="{'group_by':'entry_date:month'}"/>
                </group>
            </search>
        </field>
    </record>

    <record id="project_timesheet_forecast_report_action" model="ir.actions.act_window">
        <field name="name">Timesheet Planning Analysis</field>
        <field name="res_model">project.timesheet.forecast.report.analysis</field>
        <field name="view_mode">graph,pivot</field>
        <field name="search_view_id" ref="project_timesheet_forecast_report_view_search"/>
        <field name="context">{
            'pivot_row_groupby': ['employee_id'],
            'pivot_col_groupby': ['entry_date', 'line_type'],
            'pivot_measures': ['number_hours'],
            'group_by': ['entry_date:month', 'line_type'],
            'search_default_year': True,

        }</field>
        <field name="help">This report performs analysis on your timesheet and planning. This allow to have a global view of past forecast and what was really done. Comparing old estimation and effective work amount will help you to better plan your futur project.</field>
    </record>

    <menuitem id="menu_project_timesheet_forecast_report_analysis"
        name="Timesheet and Planning Analysis"
        parent="project.menu_project_report"
        action="project_timesheet_forecast_report_action"/>

</odoo>
