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

        <!--     Opportunity tree view  -->
        <record id="view_report_crm_lead_assign_filter" model="ir.ui.view">
            <field name="name">crm.lead.report.assign.select</field>
            <field name="model">crm.lead.report.assign</field>
            <field name="arch" type="xml">
                <search string="Leads Analysis">
                    <filter icon="terp-check" string="Current" domain="[('state','in',('draft','open'))]"/>
                    <filter icon="terp-dialog-close" string="Closed" domain="[('state','=','done')]"/>
                    <field name="section_id" context="{'invisible_section': False}"/>
                    <field name="grade_id"/>
                    <field name="user_id"/>
                    <field name="partner_assigned_id"/>
                    <group  expand="0" string="Extended Filters...">
                      <field name="partner_id"/>
                      <separator/>
                      <field name="stage_id" widget="selection" domain="[('section_ids', '=', 'section_id')]"/>
                      <separator />
                      <field name="company_id" widget="selection" groups="base.group_multi_company"/>
                      <field name="creation_date"/>
                      <field name="opening_date"/>
                      <field name="date_closed"/>
                    </group>
                    <group  expand="1" string="Group By...">
                        <filter string="Salesperson" name="user" icon="terp-personal"
                            domain="[]" context="{'group_by':'user_id'}" />
                        <filter string="Partner" icon="terp-partner" context="{'group_by':'partner_assigned_id'}" />
                        <filter string="Country" icon="terp-go-home" context="{'group_by':'country_id'}" />
                        <filter string="Section" icon="terp-personal+"
                                domain="[]"
                                context="{'group_by':'section_id'}" />
                        <filter string="Grade" name="group_grade" icon="terp-stock_symbol-selection"
                                domain="[]" context="{'group_by':'grade_id'}" />
                        <filter string="Stage" icon="terp-stage" domain="[]" context="{'group_by':'stage_id'}"/>
                        <filter string="Priority"  icon="terp-rating-rated" domain="[]" context="{'group_by':'priority'}" />
                        <filter string="Status" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}" />
                        <filter string="Company" icon="terp-go-home" domain="[]" context="{'group_by':'company_id'}" />
                        <filter string="Assign Date" icon="terp-go-today" domain="[]" name="group_partner_date" context="{'group_by':'date_assign'}"/>
                        <filter string="Day" icon="terp-go-today" domain="[]" context="{'group_by':'day'}"/>
                        <filter string="Month" icon="terp-go-month" domain="[]" context="{'group_by':'month'}" />
                        <filter string="Year" icon="terp-go-year" domain="[]" context="{'group_by':'year'}" />
                    </group>
                </search>
            </field>
        </record>

<!-- Crm Lead Assign report Graph View -->

        <record id="view_report_crm_lead_assign_graph" model="ir.ui.view">
            <field name="name">crm.lead.assign.graph</field>
            <field name="model">crm.lead.report.assign</field>
            <field name="arch" type="xml">
                <graph orientation="horizontal" string="Lead Assign" type="bar">
                    <field name="state"/>
                    <field name="nbr" operator="+"/>
                    <field group="True" name="user_id"/>
                </graph>
            </field>
        </record>

        <record id="view_report_crm_opportunity_assign_tree" model="ir.ui.view">
            <field name="name">crm.lead.assign.report.tree</field>
            <field name="model">crm.lead.report.assign</field>
            <field name="arch" type="xml">
            <tree string="Opportunities Assignment Analysis" create="false">
                <field name="year" invisible="1"/>
                <field name="month" invisible="1"/>
                <field name="date_assign" invisible="1"/>
                <field name="section_id" invisible="1"/>
                <field name="user_id" invisible="1"/>
                <field name="grade_id" invisible="1" widget="selection"/>
                <field name="partner_assigned_id" invisible="1"/>
                <field name="partner_id" invisible="1"/>
                <field name="country_id" invisible="1"/>
                <field name="day" invisible="1"/>
                <field name="state"  invisible="1"/>
                <field name="stage_id"  invisible="1"/>
                <field name="priority"  invisible="1"/>
                <field name="type" invisible="1"/>
                <field name="company_id" invisible="1" groups="base.group_multi_company"/>
                <field name="nbr" string="#Opportunities" sum="#Opportunities"/>
                <field name="planned_revenue" sum="Planned Revenues"/>
                <field name="delay_open" sum='Delay to open'/>
                <field name="delay_close" sum='Delay to close'/>
                <field name="delay_expected"/>
                <field name="probability" widget="progressbar"/>
                <field name="probability_max" widget="progressbar"/>
                <field name="probable_revenue"/>
             </tree>
            </field>
       </record>

       <!-- Leads by user and section Action -->

       <record id="action_report_crm_opportunity_assign" model="ir.actions.act_window">
            <field name="name">Opp. Assignment Analysis</field>
            <field name="res_model">crm.lead.report.assign</field>
            <field name="view_type">form</field>
            <field name="context">{'default_type': 'opportunity', "search_default_group_partner_date": 1, "search_default_group_grade":1,'group_by_no_leaf':1,'group_by':[]}</field>
            <field name="view_mode">tree</field>
            <field name="domain">[('type', '=', 'opportunity')]</field>
        </record>

       <record model="ir.actions.act_window.view" id="action_report_crm_opportunity_assign_tree">
            <field name="sequence" eval="1"/>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="view_report_crm_opportunity_assign_tree"/>
            <field name="act_window_id" ref="action_report_crm_opportunity_assign"/>
       </record>

       <record model="ir.actions.act_window.view" id="action_report_crm_lead_assign_graph">
            <field name="sequence" eval="2"/>
            <field name="view_mode">graph</field>
            <field name="view_id" ref="view_report_crm_lead_assign_graph"/>
            <field name="act_window_id" ref="action_report_crm_opportunity_assign"/>
       </record>

       <menuitem id="menu_report_crm_opportunities_assign_tree"
           parent="base.next_id_64" action="action_report_crm_opportunity_assign" sequence="20"/>

    </data>
</openerp>
