<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="timesheets_analysis_report_pivot_employee" model="ir.ui.view">
            <field name="name">timesheets.analysis.report.pivot</field>
            <field name="model">timesheets.analysis.report</field>
            <field name="arch" type="xml">
                <pivot string="Timesheets Analysis" sample="1" disable_linking="True">
                    <field name="employee_id" type="row"/>
                    <field name="date" interval="month" type="col"/>
                    <field name="amount" string="Timesheet Costs"/>
                    <field name="unit_amount" type="measure" widget="timesheet_uom"/>
                </pivot>
            </field>
        </record>

        <record id="timesheets_analysis_report_graph_employee" model="ir.ui.view">
            <field name="name">timesheets.analysis.report.graph</field>
            <field name="model">timesheets.analysis.report</field>
            <field name="arch" type="xml">
                <graph string="Timesheets" sample="1" js_class="hr_timesheet_graphview" disable_linking="True">
                    <field name="employee_id" type="row"/>
                    <field name="amount" string="Timesheet Costs"/>
                    <field name="unit_amount" type="measure" widget="timesheet_uom"/>
                </graph>
            </field>
        </record>

        <record id="timesheets_analysis_report_pivot_project" model="ir.ui.view">
            <field name="name">timesheets.analysis.report.pivot</field>
            <field name="model">timesheets.analysis.report</field>
            <field name="arch" type="xml">
                <pivot string="Timesheets Analysis" sample="1" disable_linking="True">
                    <field name="project_id" type="row"/>
                    <field name="date" interval="month" type="col"/>
                    <field name="amount" string="Timesheet Costs"/>
                    <field name="unit_amount" type="measure" widget="timesheet_uom"/>
                </pivot>
            </field>
        </record>

        <record id="timesheets_analysis_report_graph_project" model="ir.ui.view">
            <field name="name">timesheets.analysis.report.graph</field>
            <field name="model">timesheets.analysis.report</field>
            <field name="arch" type="xml">
                <graph string="Timesheets" sample="1" js_class="hr_timesheet_graphview" disable_linking="True">
                    <field name="project_id" type="row"/>
                    <field name="amount" string="Timesheet Costs"/>
                    <field name="unit_amount" type="measure" widget="timesheet_uom"/>
                </graph>
            </field>
        </record>

        <record id="timesheets_analysis_report_pivot_task" model="ir.ui.view">
            <field name="name">timesheets.analysis.report.pivot</field>
            <field name="model">timesheets.analysis.report</field>
            <field name="arch" type="xml">
                <pivot string="Timesheets Analysis" sample="1" disable_linking="True">
                    <field name="amount" string="Timesheet Costs"/>
                    <field name="project_id" type="row"/>
                    <field name="task_id" type="row"/>
                    <field name="date" interval="month" type="col"/>
                    <field name="unit_amount" type="measure" widget="timesheet_uom"/>
                </pivot>
            </field>
        </record>

        <record id="timesheets_analysis_report_graph_task" model="ir.ui.view">
            <field name="name">timesheets.analysis.report.graph</field>
            <field name="model">timesheets.analysis.report</field>
            <field name="arch" type="xml">
                <graph string="Timesheets" sample="1" js_class="hr_timesheet_graphview" disable_linking="True">
                    <field name="project_id" type="row"/>
                    <field name="task_id" type="row"/>
                    <field name="amount" string="Timesheet Costs"/>
                    <field name="unit_amount" type="measure" widget="timesheet_uom"/>
                </graph>
            </field>
        </record>

        <record id="hr_timesheet_report_search" model="ir.ui.view">
            <field name="name">timesheets.analysis.report.search</field>
            <field name="model">timesheets.analysis.report</field>
            <field name="arch" type="xml">
                <search string="Timesheet">
                    <field name="date"/>
                    <field name="employee_id"/>
                    <field name="project_id"/>
                    <field name="ancestor_task_id" groups="project.group_subtask_project"/>
                    <field name="task_id"/>
                    <field name="name"/>
                    <field name="department_id"/>
                    <field name="manager_id"/>
                    <filter name="mine" string="My Timesheets" domain="[('user_id', '=', uid)]"/>
                    <separator/>
                    <filter name="month" string="Date" date="date"/>
                    <group expand="0" string="Group By">
                        <filter string="Project" name="groupby_project" domain="[]" context="{'group_by': 'project_id'}"/>
                        <filter string="Ancestor Task" name="groupby_parent_task" domain="[]" context="{'group_by': 'ancestor_task_id'}" groups="project.group_subtask_project"/>
                        <filter string="Task" name="groupby_task" domain="[]" context="{'group_by': 'task_id'}"/>
                        <filter string="Date" name="groupby_date" domain="[]" context="{'group_by': 'date'}" help="Timesheet by Date"/>
                        <filter string="Department" name="groupby_department" domain="[]" context="{'group_by': 'department_id'}"/>
                        <filter string="Manager" name="groupby_manager" domain="[]" context="{'group_by': 'manager_id'}"/>
                        <filter string="Employee" name="groupby_employee" domain="[]" context="{'group_by': 'employee_id'}"/>
                    </group>
                </search>
            </field>
        </record>

        <!-- Group by employee -->
        <record id="act_hr_timesheet_report" model="ir.actions.act_window">
            <field name="name">Timesheets by Employee</field>
            <field name="res_model">timesheets.analysis.report</field>
            <field name="domain">[('project_id', '!=', False)]</field>
            <field name="context">{}</field>
            <field name="search_view_id" ref="hr_timesheet_report_search"/>
            <field name="view_mode">pivot,graph</field>
            <field name="help" type="html">
              <p class="o_view_nocontent_empty_folder">
                No data yet!
              </p><p>
                Analyze the projects and tasks on which your employees spend their time.<br/>
                Evaluate which part is billable and what costs it represents.
              </p>
            </field>
        </record>

        <record model="ir.actions.act_window.view" id="act_hr_timesheet_report_pivot">
            <field name="sequence" eval="5"/>
            <field name="view_mode">pivot</field>
            <field name="view_id" ref="hr_timesheet.timesheets_analysis_report_pivot_employee"/>
            <field name="act_window_id" ref="act_hr_timesheet_report"/>
        </record>

        <record id="timesheet_action_view_report_by_employee_graph" model="ir.actions.act_window.view">
            <field name="sequence" eval="6"/>
            <field name="view_mode">graph</field>
            <field name="view_id" ref="hr_timesheet.timesheets_analysis_report_graph_employee"/>
            <field name="act_window_id" ref="act_hr_timesheet_report"/>
        </record>

        <!-- Group by project-->
        <record id="timesheet_action_report_by_project" model="ir.actions.act_window">
            <field name="name">Timesheets by Project</field>
            <field name="res_model">timesheets.analysis.report</field>
            <field name="domain">[('project_id', '!=', False)]</field>
            <field name="context">{}</field>
            <field name="search_view_id" ref="hr_timesheet_report_search"/>
            <field name="view_mode">pivot,graph</field>
            <field name="help" type="html">
              <p class="o_view_nocontent_empty_folder">
                No data yet!
              </p><p>
                Analyze the projects and tasks on which your employees spend their time.<br/>
                Evaluate which part is billable and what costs it represents.
              </p>
            </field>
        </record>

        <record id="timesheet_action_view_report_by_project_pivot" model="ir.actions.act_window.view">
            <field name="sequence" eval="5"/>
            <field name="view_mode">pivot</field>
            <field name="view_id" ref="hr_timesheet.timesheets_analysis_report_pivot_project"/>
            <field name="act_window_id" ref="timesheet_action_report_by_project"/>
        </record>

        <record id="timesheet_action_view_report_by_project_graph" model="ir.actions.act_window.view">
            <field name="sequence" eval="6"/>
            <field name="view_mode">graph</field>
            <field name="view_id" ref="hr_timesheet.timesheets_analysis_report_graph_project"/>
            <field name="act_window_id" ref="timesheet_action_report_by_project"/>
        </record>

        <!-- Group by task -->
        <record id="timesheet_action_report_by_task" model="ir.actions.act_window">
            <field name="name">Timesheets by Task</field>
            <field name="res_model">timesheets.analysis.report</field>
            <field name="domain">[('project_id', '!=', False)]</field>
            <field name="context">{}</field>
            <field name="search_view_id" ref="hr_timesheet_report_search"/>
            <field name="view_mode">pivot,graph</field>
            <field name="help" type="html">
              <p class="o_view_nocontent_empty_folder">
                No data yet!
              </p><p>
                Analyze the projects and tasks on which your employees spend their time.<br/>
                Evaluate which part is billable and what costs it represents.
              </p>
            </field>
        </record>

        <record id="timesheet_action_view_report_by_task_pivot" model="ir.actions.act_window.view">
            <field name="sequence" eval="5"/>
            <field name="view_mode">pivot</field>
            <field name="view_id" ref="hr_timesheet.timesheets_analysis_report_pivot_task"/>
            <field name="act_window_id" ref="timesheet_action_report_by_task"/>
        </record>

        <record id="timesheet_action_view_report_by_task_graph" model="ir.actions.act_window.view">
            <field name="sequence" eval="6"/>
            <field name="view_mode">graph</field>
            <field name="view_id" ref="hr_timesheet.timesheets_analysis_report_graph_task"/>
            <field name="act_window_id" ref="timesheet_action_report_by_task"/>
        </record>

        <menuitem id="menu_timesheets_reports"
            name="Reporting"
            parent="timesheet_menu_root"
            sequence="99"/>

        <menuitem id="menu_timesheets_reports_timesheet"
            name="Timesheets"
            parent="menu_timesheets_reports"
            sequence="10"/>

        <menuitem id="menu_hr_activity_analysis"
            parent="menu_timesheets_reports_timesheet"
            action="act_hr_timesheet_report"
            groups="hr_timesheet.group_hr_timesheet_approver"
            name="By Employee"
            sequence="10"/>

        <menuitem id="timesheet_menu_report_timesheet_by_project"
            parent="menu_timesheets_reports_timesheet"
            action="timesheet_action_report_by_project"
            name="By Project"
            sequence="15"/>

        <menuitem id="timesheet_menu_report_timesheet_by_task"
            parent="menu_timesheets_reports_timesheet"
            action="timesheet_action_report_by_task"
            name="By Task"
            sequence="20"/>

    </data>
</odoo>
