<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="view_report_crm_phonecall_graph" model="ir.ui.view">
        <field name="name">crm.phonecall.report.graph</field>
        <field name="model">crm.phonecall.report</field>
        <field name="arch" type="xml">
            <graph stacked="True" string="Phone calls">
                <field name="team_id" type="row" />
                <field interval="month" name="create_date" type="col" />
                <field name="nbr_cases" type="measure" />
                <field name="duration" type="measure" />
            </graph>
        </field>
    </record>
    <record id="view_report_crm_phonecall_pivot" model="ir.ui.view">
        <field name="name">crm.phonecall.report.pivot</field>
        <field name="model">crm.phonecall.report</field>
        <field name="arch" type="xml">
            <pivot disable_linking="True" string="Phone calls">
                <field name="team_id" type="row" />
                <field interval="month" name="create_date" type="col" />
                <field name="nbr_cases" type="measure" />
                <field name="duration" type="measure" />
            </pivot>
        </field>
    </record>
    <record id="filter_crm_phonecall_sales_team" model="ir.filters">
        <field name="name">By Sales Team</field>
        <field name="model_id">crm.phonecall.report</field>
        <field name="domain">[('state','=','done')]</field>
        <field eval="False" name="user_id" />
        <field name="context">
            {'group_by': ['team_id'], 'measures': ['nbr_cases', 'duration']}
        </field>
    </record>
    <record id="filter_crm_phonecall_delay_to_close" model="ir.filters">
        <field name="name">Delay To Close</field>
        <field name="model_id">crm.phonecall.report</field>
        <field name="domain">[('state','=','done')]</field>
        <field eval="False" name="user_id" />
        <field name="context">
            {'group_by': ['team_id'], 'measures': ['delay_close']}
        </field>
    </record>
    <record id="filter_crm_phonecall_phone_call_to_do" model="ir.filters">
        <field name="name">Phone Calls To Do</field>
        <field name="model_id">crm.phonecall.report</field>
        <field name="domain">[('state','in',('draft','open'))]</field>
        <field eval="False" name="user_id" />
        <field name="context">
            {'group_by': ['team_id'], 'measures': ['nbr_cases']}
        </field>
    </record>
    <record id="view_report_crm_phonecall_filter" model="ir.ui.view">
        <field name="name">crm.phonecall.report.select</field>
        <field name="model">crm.phonecall.report</field>
        <field name="arch" type="xml">
            <search string="Search">
                <filter
                    domain="[('state','in',('draft','open'))]"
                    help="Phone calls which are in draft and open state"
                    name="todo"
                    string="Todo"
                />
                <filter
                    domain="[('state','=','done')]"
                    help="Phone calls which are in closed state"
                    name="held"
                    string="Held"
                />
                <filter
                    domain="[('state','=','pending')]"
                    help="Phone calls which are in pending state"
                    name="not_held"
                    string="Not Held"
                />
                <separator />
                <filter
                    context="{'invisible_section': False}"
                    domain="[('team_id.user_id','=',uid)]"
                    groups="sales_team.group_sale_manager"
                    help="Phone calls that are assigned to one of the sale teams I manage"
                    name="my_sales_team"
                    string="My Sales Team(s)"
                />
                <separator />
                <filter
                    domain="[('user_id','=',uid)]"
                    help="Phone Calls that are assigned to me"
                    name="my_phone_calls"
                    string="My Phone Calls"
                />
                <field
                    context="{'invisible_section': False}"
                    groups="sales_team.group_sale_manager"
                    name="team_id"
                    string="Sales Team"
                />
                <field name="user_id" string="Salesperson" />
                <group expand="0" string="Extended Filters...">
                    <field
                        filter_domain="[('partner_id','child_of',self)]"
                        name="partner_id"
                    />
                    <field groups="base.group_multi_company" name="company_id" />
                    <field name="opening_date" />
                    <field name="date_closed" />
                </group>
                <group expand="1" string="Group By">
                    <filter
                        context="{'group_by':'user_id'}"
                        name="Salesperson"
                        string="Salesperson"
                    />
                    <filter
                        context="{'group_by':'team_id'}"
                        groups="sales_team.group_sale_manager"
                        name="sales_team"
                        string="Sales Team"
                    />
                    <filter
                        context="{'group_by':'partner_id'}"
                        name="customer"
                        string="Customer"
                    />
                    <filter
                        context="{'group_by':'state'}"
                        name="status"
                        string="Status"
                    />
                    <separator />
                    <filter
                        context="{'group_by':'create_date:month'}"
                        help="Month of call"
                        name="creation_month"
                        string="Creation Month"
                    />
                </group>
            </search>
        </field>
    </record>
    <record id="crm_phonecall_report_action" model="ir.actions.act_window">
        <field name="name">Phone Calls Analysis</field>
        <field name="res_model">crm.phonecall.report</field>
        <field name="view_mode">pivot,graph</field>
    </record>
    <record id="crm_phonecall_report_action_team" model="ir.actions.act_window">
        <field name="name">Phone Calls Analysis</field>
        <field name="res_model">crm.phonecall.report</field>
        <field name="view_mode">pivot,graph</field>
        <field name="context">{'search_default_team_id': active_id}</field>
    </record>
    <menuitem
        action="crm_phonecall_report_action"
        groups="sales_team.group_sale_salesman"
        id="menu_report_crm_phonecalls_tree"
        name="Phone Calls Analysis"
        parent="crm.crm_menu_report"
        sequence="15"
    />
</odoo>
