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

    <record id="timesheets_analysis_report_pivot_inherit" model="ir.ui.view">
        <field name="name">timesheets.analysis.report.pivot</field>
        <field name="model">timesheets.analysis.report</field>
        <field name="inherit_id" ref="hr_timesheet.timesheets_analysis_report_pivot_employee"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='unit_amount']" position="after">
                <field name="billable_time" widget="timesheet_uom"/>
                <field name="non_billable_time" widget="timesheet_uom"/>
            </xpath>
        </field>
    </record>

    <record id="timesheets_analysis_report_graph_inherit" model="ir.ui.view">
        <field name="name">timesheets.analysis.report.graph</field>
        <field name="model">timesheets.analysis.report</field>
        <field name="inherit_id" ref="hr_timesheet.timesheets_analysis_report_pivot_employee"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='unit_amount']" position="after">
                <field name="billable_time" widget="timesheet_uom"/>
                <field name="non_billable_time" widget="timesheet_uom"/>
            </xpath>
        </field>
    </record>

    <!--TO DO: Remove in master and update existing inherit_id-->
    <record id="timesheets_analysis_report_graph_timesheet_grid" model="ir.ui.view">
        <field name="name">timesheets.analysis.report.graph</field>
        <field name="model">timesheets.analysis.report</field>
        <field name="inherit_id" ref="hr_timesheet.timesheets_analysis_report_graph_employee"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='unit_amount']" position="after">
                <field name="billable_time" widget="timesheet_uom"/>
                <field name="non_billable_time" widget="timesheet_uom"/>
            </xpath>
        </field>
    </record>


    <record id="timesheets_analysis_report_pivot_project_inherit" model="ir.ui.view">
        <field name="name">timesheets.analysis.report.pivot.project</field>
        <field name="model">timesheets.analysis.report</field>
        <field name="inherit_id" ref="hr_timesheet.timesheets_analysis_report_pivot_project"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='unit_amount']" position="after">
                <field name="billable_time" widget="timesheet_uom"/>
                <field name="non_billable_time" widget="timesheet_uom"/>
            </xpath>
        </field>
    </record>

    <record id="timesheets_analysis_report_graph_project_inherit" model="ir.ui.view">
        <field name="name">timesheets.analysis.report.graph.project</field>
        <field name="model">timesheets.analysis.report</field>
        <field name="inherit_id" ref="hr_timesheet.timesheets_analysis_report_graph_project"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='unit_amount']" position="after">
                <field name="billable_time" widget="timesheet_uom"/>
                <field name="non_billable_time" widget="timesheet_uom"/>
            </xpath>
        </field>
    </record>

    <record id="timesheets_analysis_report_pivot_task_inherit" model="ir.ui.view">
        <field name="name">timesheets.analysis.report.pivot.task</field>
        <field name="model">timesheets.analysis.report</field>
        <field name="inherit_id" ref="hr_timesheet.timesheets_analysis_report_pivot_task"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='unit_amount']" position="after">
                <field name="billable_time" widget="timesheet_uom"/>
                <field name="non_billable_time" widget="timesheet_uom"/>
            </xpath>
        </field>
    </record>

    <record id="timesheets_analysis_report_graph_task_inherit" model="ir.ui.view">
        <field name="name">timesheets.analysis.report.graph.task</field>
        <field name="model">timesheets.analysis.report</field>
        <field name="inherit_id" ref="hr_timesheet.timesheets_analysis_report_graph_task"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='unit_amount']" position="after">
                <field name="billable_time" widget="timesheet_uom"/>
                <field name="non_billable_time" widget="timesheet_uom"/>
            </xpath>
        </field>
    </record>

    <record id="timesheets_analysis_report_pivot_invoice_type" 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="date" interval="month" type="row"/>
                <field name="timesheet_invoice_type" type="col"/>
                <field name="amount" string="Timesheet Costs"/>
                <field name="unit_amount" type="measure" widget="timesheet_uom"/>
                <field name="billable_time" widget="timesheet_uom"/>
                <field name="non_billable_time" widget="timesheet_uom"/>
            </pivot>
        </field>
    </record>

    <record id="timesheets_analysis_report_graph_invoice_type" 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="amount" string="Timesheet Costs"/>
                <field name="unit_amount" type="measure" widget="timesheet_uom"/>
                <field name="billable_time" widget="timesheet_uom"/>
                <field name="non_billable_time" widget="timesheet_uom"/>
                <field name="timesheet_invoice_type" type="row"/>
            </graph>
        </field>
    </record>

    <record id="hr_timesheet_report_search_sale_timesheet" model="ir.ui.view">
        <field name="name">timesheets.analysis.report.search</field>
        <field name="model">timesheets.analysis.report</field>
        <field name="inherit_id" ref="hr_timesheet.hr_timesheet_report_search"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='task_id']" position="after">
                <field name="order_id" string="Sales Order" groups="sales_team.group_sale_salesman"/>
                <field name="so_line" groups="sales_team.group_sale_salesman"/>
            </xpath>
            <xpath expr="//filter[@name='month']" position="before">
                <filter name="billable_fixed" string="Billed at a Fixed Price" domain="[('timesheet_invoice_type', '=', 'billable_fixed')]"
                    groups="sales_team.group_sale_salesman"/>
                <filter name="billable_time" string="Billed on Timesheets" domain="[('timesheet_invoice_type', '=', 'billable_time')]"
                    groups="sales_team.group_sale_salesman"/>
                <filter name="billable_milestones" string="Billed on Milestones" domain="[('timesheet_invoice_type', '=', 'billable_milestones')]"
                    groups="sales_team.group_sale_salesman"/>
                <filter name="billable_manual" string="Billed Manually" domain="[('timesheet_invoice_type', '=', 'billable_manual')]"
                    groups="sales_team.group_sale_salesman"/>
                <filter name="non_billable" string="Non-Billable" domain="[('timesheet_invoice_type', '=', 'non_billable')]"
                    groups="sales_team.group_sale_salesman"/>
                <separator/>
            </xpath>
            <xpath expr="//filter[@name='groupby_employee']" position="after">
                <filter string="Sales Order" name="groupby_sale_order" domain="[]"
                    context="{'group_by': 'order_id'}" groups="sales_team.group_sale_salesman"/>
                <filter string="Sales Order Item" name="groupby_sale_order_item" domain="[]"
                    context="{'group_by': 'so_line'}" groups="sales_team.group_sale_salesman"/>
                <filter string="Invoice" name="groupby_invoice" domain="[]"
                    context="{'group_by': 'timesheet_invoice_id'}" groups="sales_team.group_sale_salesman"/>
                <filter string="Billable Type" name="groupby_timesheet_invoice_type" domain="[]"
                    context="{'group_by': 'timesheet_invoice_type'}" groups="sales_team.group_sale_salesman"/>
            </xpath>
        </field>
    </record>

    <record id="timesheet_action_billing_report" model="ir.actions.act_window">
        <field name="name">Timesheets by Billing Type</field>
        <field name="res_model">timesheets.analysis.report</field>
        <field name="domain">[('project_id', '!=', False)]</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No data yet!
            </p>
            <p>Review your timesheets by billing type and make sure your time is billable.</p>
        </field>
        <field name="search_view_id" ref="hr_timesheet.hr_timesheet_report_search"/>
        <field name="view_mode">pivot,graph</field>
    </record>

    <record id="timesheet_action_view_report_by_billing_rate_pivot" model="ir.actions.act_window.view">
        <field name="sequence" eval="5"/>
        <field name="view_mode">pivot</field>
        <field name="view_id" ref="timesheets_analysis_report_pivot_invoice_type"/>
        <field name="act_window_id" ref="timesheet_action_billing_report"/>
    </record>

    <record id="timesheet_action_view_report_by_billing_rate_graph" model="ir.actions.act_window.view">
        <field name="sequence" eval="6"/>
        <field name="view_mode">graph</field>
        <field name="view_id" ref="timesheets_analysis_report_graph_invoice_type"/>
        <field name="act_window_id" ref="timesheet_action_billing_report"/>
    </record>

    <menuitem id="menu_timesheet_billing_analysis"
            parent="hr_timesheet.menu_timesheets_reports_timesheet"
            action="timesheet_action_billing_report"
            name="By Billing Type"
            sequence="40"/>

</odoo>
