<?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="type">search</field>
            <field name="arch" type="xml">
                <search string="Leads Analysis">
                    <group col="20" colspan="8">
                        <filter string="Last 30 Days" icon="terp-go-month" name="this_month"
                            domain="[('create_date','&gt;',(datetime.date.today()-datetime.timedelta(days=30)).strftime('%%Y-%%m-%%d'))]"/>
                        <filter icon="terp-go-week" string="7 Days" separator="1"
                            domain="[('create_date','&gt;',(datetime.date.today()-datetime.timedelta(days=7)).strftime('%%Y-%%m-%%d'))]"/>
                        <separator orientation="vertical" />
                        <filter icon="terp-check"
                            string="Current"
                            domain="[('state','in',('draft','open'))]"/>
                        <filter icon="terp-dialog-close"
                            string="Closed"
                            domain="[('state','=','done')]"/>
                        <separator orientation="vertical" />
                        <field name="section_id"
                            widget="selection"
                            context="{'invisible_section': False}"/>
                        <field name="grade_id"/>
                        <field name="user_id"/>
                        <field name="partner_assigned_id"/>
                   </group>
                   <newline/>
                   <group  expand="0" string="Extended Filters..." groups="base.group_extended">
                      <field name="partner_id"/>
                      <separator orientation="vertical"/>
                      <field name="stage_id" widget="selection" domain="[('section_ids', '=', 'section_id')]"/>
                      <field name="categ_id" widget="selection" domain="[('object_id.model', '=', 'crm.lead')]"/>
                      <separator orientation="vertical"/>
                      <field name="company_id" widget="selection" groups="base.group_multi_company"/>
                      <newline/>
                      <field name="creation_date"/>
                      <field name="opening_date"/>
                      <field name="date_closed"/>
                   </group>
                   <newline/>
                   <group  expand="1" string="Group By...">
                       <filter string="Salesman" 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'}" />
                        <separator orientation="vertical" />
                        <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="Category" icon="terp-stock_symbol-selection"
                            domain="[]" context="{'group_by':'categ_id'}" />

                        <separator orientation="vertical" />
                        <filter string="Stage" icon="terp-stage" domain="[]" context="{'group_by':'stage_id'}"/>
                        <separator orientation="vertical"/>
                        <filter string="Priority"  icon="terp-rating-rated" domain="[]" context="{'group_by':'priority'}" />
                        <separator orientation="vertical" />
                        <filter string="State" icon="terp-stock_effects-object-colorize"
                            domain="[]" context="{'group_by':'state'}" />
                        <separator orientation="vertical" />
                        <filter string="Company" icon="terp-go-home"
                            domain="[]"
                            context="{'group_by':'company_id'}" />
                        <separator orientation="vertical" />
                        <filter string="Assign Date" icon="terp-go-today"
                            domain="[]"
                            name="group_partner_date"
                            context="{'group_by':'date_assign'}"/>
                        <separator orientation="vertical"/>
                        <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="type">graph</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="type">tree</field>
            <field name="arch" type="xml">
            <tree string="Opportunities Assignment Analysis">
                <field name="year" invisible="1"/>
                <field name="month" invisible="1"/>
                <field name="date_assign" invisible="1"/>
                <field name="section_id" invisible="1" groups="base.group_extended"/>
                <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="categ_id" 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">{"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"
           groups="base.group_extended"
           parent="base.next_id_64" action="action_report_crm_opportunity_assign" sequence="5"/>

    </data>
</openerp>
