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

<!-- Phone calls by user and section Tree View -->

        <record id="view_report_crm_phonecall_tree" model="ir.ui.view">
            <field name="name">crm.phonecall.report.tree</field>
            <field name="model">crm.phonecall.report</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
               <tree string="Phone calls">
                    <field name="name" invisible="1"/>
                    <field name="month" invisible="1"/>
                    <field name="section_id" invisible="1"/>
                    <field name="priority" invisible="1"/>
                    <field name="stage_id" invisible="1"/>
                    <field name="user_id" invisible="1"/>
                    <field name="company_id" invisible="1"/>
                    <field name="partner_id" invisible="1"/>
                    <field name="state" invisible="1"/>
                    <field name="categ_id" invisible="1"/>
                    <field name="day" invisible="1"/>
                    <field name="nbr" string="#Phone calls" sum="#Phone calls"/>
                    <field name="duration" avg="Duration"/>
                    <field name="delay_close" avg="Avg Closing Delay"/>
                    <field name="delay_open" sum='Delay to open'/>
              </tree>
            </field>
        </record>

<!-- Phone calls by user and section Form View -->

        <record id="view_report_crm_phonecall_form" model="ir.ui.view">
            <field name="name">crm.phonecall.report.form</field>
            <field name="model">crm.phonecall.report</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Cases">
                    <field name="name" select="1"/>
                    <field name="month" select="1"/>
                    <field name="user_id" select="1"/>
                    <field name="section_id" select="1"/>
                    <field name="nbr" select="1"/>
                   <field name="delay_close"/>
                    <field name="amount_revenue"/>
                    <field name="amount_revenue_prob"/>
                    <field name="probability"/>
                    <field name="state" select="1"/>
                </form>
            </field>
        </record>

<!-- Phone calls by user and section Graph View -->

        <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="type">graph</field>
            <field name="arch" type="xml">
                <graph orientation="horizontal" string="Phone calls" type="bar">
                    <field name="state"/>
                    <field name="nbr" operator="+"/>
                    <field group="True" name="user_id"/>
                </graph>
            </field>
        </record>

<!-- Phone calls by user and section Search View -->

    <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="type">search</field>
            <field name="arch" type="xml">
                <search string="Search">
                  <group col="16" colspan="8">
                           <filter string="  Year  " icon="terp-go-year"
                               domain="[('create_date','&lt;=', time.strftime('%%Y-%%m-%%d')),('create_date','&gt;=',time.strftime('%%Y-01-01'))]"
                               help="Phone calls made in current year"/>

                       <filter string="   Month   " icon="terp-go-month" name="This Month"
                           domain="[('create_date','&lt;=', time.strftime('%%Y-%%m-%%d')),('create_date','&gt;=',time.strftime('%%Y-%%m-01'))]"
                           help="Phone calls made in current month"/>

                       <filter icon="terp-go-month" string="    Month-1    " separator="1"
                            domain="[('create_date','&lt;=', (datetime.date (int(time.strftime('%%Y')), datetime.date.today().month, 1) - datetime.timedelta (days = 1)).strftime('%%Y-%%m-%%d')),('create_date','&gt;',(datetime.date (int(time.strftime('%%Y')), datetime.date.today().month-1, 1)).strftime('%%Y-%%m-%%d'))]"
                            help="Phone calls made in last month"/>

                           <separator orientation="vertical" />
                        <filter icon="terp-check"
                            string="Todo"
                            domain="[('state','in',('draft','open'))]"
                            help="Phone calls which are in draft and open state"/>
                        <filter icon="gtk-media-pause"
                            string="Not Held"
                            domain="[('state','=','pending')]"
                            help="Phone calls which are in pending state"/>
                        <filter icon="terp-camera_test"
                            string="Held"
                            domain="[('state','=','done')]"
                            help="Phone calls which are in closed state"/>
                      <separator orientation="vertical" />
                        <field name="section_id" string="Sales Team"
                            default="context.get('section_id', False)"
                            context="{'invisible_section': False}">               
                       <filter icon="terp-personal+"
                           context="{'invisible_section': False}"
                           domain="[('section_id.user_id','=',uid)]"
                           help="My team" />
                        </field>   
                          <field name="user_id" string="Salesman" select="1">
                            <filter icon="terp-crm" string="My Case" help="My Case" domain="[('user_id','=',uid)]" />
                           </field>
                   </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="[('object_id.model', '=', 'crm.phonecall')]"/>
                        <field name="categ_id" widget="selection" domain="[('object_id.model', '=', 'crm.phonecall')]"/>
                        <separator orientation="vertical"/>
                        <field name="company_id" 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="User" name="User" icon="terp-personal"
                            domain="[]" context="{'group_by':'user_id'}" />
                       <filter string="Partner" icon="terp-personal" context="{'group_by':'partner_id'}" />
                        <separator orientation="vertical" />
                        <filter string="Sales Team" icon="terp-personal+"
                            domain="[]"
                            context="{'group_by':'section_id'}" />
                        
                        <separator orientation="vertical" />
                        <filter string="Priority"  icon="terp-rating-rated" domain="[]" context="{'group_by':'priority'}" />
                        <filter string="Type" icon="terp-stock_symbol-selection"
                            domain="[]" context="{'group_by':'categ_id'}" />
                        <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'}" groups="base.group_multi_company"/>
                        <separator orientation="vertical" />
                        <filter string="Day" icon="terp-go-today"
                            domain="[]" context="{'group_by':'day'}" help="Date of call"/>
                        <filter string="Month" icon="terp-go-month"
                            domain="[]" context="{'group_by':'month'}" help="Month of call"/>
                        <filter string="Year" icon="terp-go-year"
                            domain="[]" context="{'group_by':'name'}" help="Year of call"/>
                  </group>
               </search>
            </field>
        </record>

<!-- Phone calls by user and section Action -->

        <record id="action_report_crm_phonecall" model="ir.actions.act_window">
            <field name="name">Phone Calls Analysis</field>
            <field name="res_model">crm.phonecall.report</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,graph</field>
            <field name="context">{"search_default_User":1,"search_default_This Month":1,'group_by_no_leaf':1,'group_by':[]}</field>
            <field name="view_id" ref="view_report_crm_phonecall_tree"/>
            <field name="search_view_id" ref="view_report_crm_phonecall_filter"/>
            <field name="help">Get an anlysis of Phone Calls number and delay to close, stage, user suits to different groups for a global or a fine grained analysis.</field>
        </record>

           <record model="ir.actions.act_window.view" id="action_report_crm_phonecall_tree">
            <field name="sequence" eval="1"/>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="view_report_crm_phonecall_tree"/>
            <field name="act_window_id" ref="action_report_crm_phonecall"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_report_crm_phonecall_graph">
            <field name="sequence" eval="2"/>
            <field name="view_mode">graph</field>
            <field name="view_id" ref="view_report_crm_phonecall_graph"/>
            <field name="act_window_id" ref="action_report_crm_phonecall"/>
        </record>

        <menuitem name="Phone Calls Analysis"
            groups="base.group_extended"
            action="action_report_crm_phonecall"
            id="menu_report_crm_phonecalls_tree" parent="base.next_id_64" sequence="5"/>

    </data>
</openerp>
