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

    <record id="sale_timesheet.project_profitability_report_view_pivot" model="ir.ui.view">
        <field name="name">project.profitability.report.pivot</field>
        <field name="model">project.profitability.report</field>
        <field name="arch" type="xml">
            <pivot string="Profitability Analysis" display_quantity="true" disable_linking="True" sample="1">
                <field name="project_id" type="row"/>
                <field name="amount_untaxed_to_invoice" type="measure"/>
                <field name="amount_untaxed_invoiced" type="measure"/>
                <field name="timesheet_cost" type="measure"/>
                <!--<field name="budgeted_unit_amount" type="measure"/>-->
            </pivot>
        </field>
    </record>

    <record id="sale_timesheet.project_profitability_report_view_graph" model="ir.ui.view">
        <field name="name">project.profitability.report.graph</field>
        <field name="model">project.profitability.report</field>
        <field name="arch" type="xml">
            <graph string="Profitability Analysis" type="bar" sample="1" disable_linking="1">
                <field name="project_id" type="row"/>
                <field name="product_id" type="col"/>
                <field name="amount_untaxed_to_invoice" type="measure"/>
                <field name="amount_untaxed_invoiced" type="measure"/>
                <field name="timesheet_cost" type="measure"/>
                <field name="other_revenues" type="measure"/>
                <field name="margin" type="measure"/>
             </graph>
         </field>
    </record>


    <record id="sale_timesheet.project_profitability_report_view_search" model="ir.ui.view">
        <field name="name">project.profitability.report.search</field>
        <field name="model">project.profitability.report</field>
        <field name="arch" type="xml">
            <search string="Profitability Analysis">
                <field name="project_id"/>
                <field name="user_id"/>
                <field name="product_id"/>
                <field name="partner_id" filter_domain="[('partner_id', 'child_of', self)]"/>
                <field name="company_id" groups="base.group_multi_company"/>
                <filter string="My Projects" name="my_project" domain="[('user_id','=', uid)]"/>
                <group expand="1" string="Group By">
                    <filter string="Project" name="group_by_project" context="{'group_by':'project_id'}"/>
                    <filter string="Project Manager" name="group_by_user_id" context="{'group_by':'user_id'}"/>
                    <filter string="Customer" name="group_by_partner_id" context="{'group_by':'partner_id'}"/>
                    <filter string="Company" name="group_by_company" context="{'group_by':'company_id'}" groups="base.group_multi_company"/>
                    <filter string="Date" name="group_by_line_date" context="{'group_by':'line_date'}"/>
                </group>
            </search>
        </field>
    </record>

    <record id="sale_timesheet.project_profitability_report_action" model="ir.actions.act_window">
        <field name="name">Project Costs and Revenues</field>
        <field name="res_model">project.profitability.report</field>
        <field name="view_mode">pivot,graph</field>
        <field name="search_view_id" ref="sale_timesheet.project_profitability_report_view_search"/>
        <field name="context">{
            'group_by_no_leaf':1,
            'group_by':[],
            'sale_show_order_product_name': 1,
        }</field>
        <field name="help">This report allows you to analyse the profitability of your projects: compare the amount to invoice, the ones already invoiced and the project cost (via timesheet cost of your employees).</field>
    </record>

    <menuitem id="sale_timesheet.menu_project_profitability_analysis"
        parent="project.menu_project_report"
        action="sale_timesheet.project_profitability_report_action"
        name="Project Costs and Revenues"
        sequence="50"/>

</odoo>
