[ADD]: Added reports for crm_opportunity. Added remaining report for crm_lead.
authoruco (OpenERP) <uco@tinyerp.co.in>
Wed, 20 Jan 2010 07:33:50 +0000 (13:03 +0530)
committeruco (OpenERP) <uco@tinyerp.co.in>
Wed, 20 Jan 2010 07:33:50 +0000 (13:03 +0530)
bzr revid: uco@tinyerp.co.in-20100120073350-qxq65ziii4dzu4qz

addons/report_crm/__init__.py
addons/report_crm/__terp__.py
addons/report_crm/report_crm.py
addons/report_crm/report_crm_lead.py
addons/report_crm/report_crm_lead_view.xml
addons/report_crm/report_crm_opportunity.py [new file with mode: 0644]
addons/report_crm/report_crm_opportunity_view.xml [new file with mode: 0644]
addons/report_crm/report_crm_view.xml

index 35390c6..7a8b9bb 100644 (file)
@@ -22,6 +22,7 @@
 import report_crm
 import report_crm_lead
 import report_crm_claim
+import report_crm_opportunity
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
index 13e55f6..eaaa5d1 100644 (file)
@@ -33,7 +33,8 @@
     'update_xml': ['security/ir.model.access.csv', 
                    'report_crm_view.xml', 
                    'report_crm_lead_view.xml',
-                   'report_crm_claim.xml',                   
+                   'report_crm_claim.xml',
+                   'report_crm_opportunity_view.xml',                   
                    ],
     'demo_xml': [],
     'installable': True, #TODO : After fixed problems , set True
index 55b4bdc..62f5d36 100644 (file)
@@ -98,36 +98,11 @@ class report_crm_case_section(osv.osv):
     _description = "Cases by Section"
     _auto = False
     
-    def _get_data(self, cr, uid, ids, field_name, arg, context={}):
-        res = {}
-        state_perc = 0.0
-        avg_ans = 0.0
-        
-        for case in self.browse(cr, uid, ids, context):
-            if field_name != 'avg_answers':
-                state = field_name[5:]
-                cr.execute("select count(*) from crm_case where section_id =%s and state='%s'"%(case.section_id.id,state))
-                state_cases = cr.fetchone()[0]
-                perc_state = (state_cases / float(case.nbr_cases) ) * 100
-                
-                res[case.id] = perc_state
-            else:
-                cr.execute('select count(*) from crm_case_log l  where l.section_id=%s'%(case.section_id.id))
-                logs = cr.fetchone()[0]
-                
-                avg_ans = logs / case.nbr_cases
-                res[case.id] = avg_ans       
-        
-        return res
-    
     _columns = {
         'name': fields.char('Year',size=64,required=False, readonly=True),
 #        'user_id':fields.many2one('res.users', 'User', readonly=True),
         'section_id':fields.many2one('crm.case.section', 'Section', readonly=True),
         'nbr_cases': fields.integer('# of Cases', readonly=True),
-        'avg_answers': fields.function(_get_data,string='Avg. Answers', method=True,type="integer"),
-       # 'perc_done': fields.function(_get_data,string='%Done', method=True,type="float"),
-#        'perc_cancel': fields.function(_get_data,string='%Cancel', method=True,type="float"),
         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
                                   ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
     }
@@ -141,8 +116,7 @@ class report_crm_case_section(osv.osv):
                     to_char(c.create_date, 'YYYY') as name,
                     to_char(c.create_date, 'MM') as month,
                     count(*) as nbr_cases,
-                    c.section_id as section_id,
-                    0 as avg_answers
+                    c.section_id as section_id
                 from
                     crm_case c
                 group by to_char(c.create_date, 'YYYY'),to_char(c.create_date, 'MM'),c.section_id
index 90586ef..1302475 100644 (file)
@@ -73,5 +73,59 @@ class report_crm_lead_categ(osv.osv):
             )""")
 report_crm_lead_categ()
 
+class report_crm_lead_section(osv.osv):
+    _name = "report.crm.lead.section"
+    _description = "Leads by Section"
+    _auto = False
+    _inherit = "report.crm.case.section"
+    
+    def _get_data(self, cr, uid, ids, field_name, arg, context={}):
+        res = {}
+        state_perc = 0.0
+        avg_ans = 0.0
+        
+        for case in self.browse(cr, uid, ids, context):
+            if field_name != 'avg_answers':
+                state = field_name[5:]
+                cr.execute("select count(*) from crm_lead where section_id =%s and state='%s'"%(case.section_id.id,state))
+                state_cases = cr.fetchone()[0]
+                perc_state = (state_cases / float(case.nbr_cases) ) * 100
+                
+                res[case.id] = perc_state
+            else:
+                cr.execute('select count(*) from crm_case_log l  where l.section_id=%s'%(case.section_id.id))
+                logs = cr.fetchone()[0]
+                
+                avg_ans = logs / case.nbr_cases
+                res[case.id] = avg_ans       
+        
+        return res
+    
+    _columns = {
+        'avg_answers': fields.function(_get_data,string='Avg. Answers', method=True,type="integer"),
+        'perc_done': fields.function(_get_data,string='%Done', method=True,type="float"),
+        'perc_cancel': fields.function(_get_data,string='%Cancel', method=True,type="float"),
+        'delay_close': fields.char('Delay to close', size=20, readonly=True),
+    }
+    _order = 'name desc, section_id'
+    def init(self, cr):
+        tools.drop_view_if_exists(cr, 'report_crm_lead_section')
+        cr.execute("""
+            create or replace view report_crm_lead_section as (
+                select
+                    min(c.id) as id,
+                    to_char(c.create_date, 'YYYY') as name,
+                    to_char(c.create_date, 'MM') as month,
+                    count(*) as nbr_cases,
+                    c.section_id as section_id,
+                    0 as avg_answers,
+                    0.0 as perc_done,
+                    0.0 as perc_cancel,
+                    to_char(avg(date_closed-c.create_date), 'DD"d" HH24:MI:SS') as delay_close
+                from
+                    crm_lead c
+                group by to_char(c.create_date, 'YYYY'),to_char(c.create_date, 'MM'),c.section_id
+            )""")
+report_crm_lead_section()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
index 76f4f59..f9f60d3 100644 (file)
         </record>
         <menuitem action="action_report_crm_lead_categ_tree" id="menu_crm_lead_categ_tree" parent="menu_crm_leads_tree"/>
         
+        <!-- Leads by Section  -->
+
+        <record id="view_report_crm_lead_section_tree" model="ir.ui.view">
+            <field name="name">report.crm.lead.section.tree</field>
+            <field name="model">report.crm.lead.section</field>
+            <field name="inherit_id" ref="view_report_crm_case_section_tree"/>
+            <field name="type">tree</field>
+            <field name="arch" type="xml">
+                <field name="nbr_cases" position="after">
+                       <field name="avg_answers"/>
+                       <field name="perc_done" select="2"/>
+                    <field name="perc_cancel" select="2"/>
+                    <field name="delay_close"/>
+                </field>
+            </field>
+        </record>
+
+        <record id="view_report_crm_lead_section_graph" model="ir.ui.view">
+            <field name="name">report.crm.lead.section.graph</field>
+            <field name="model">report.crm.lead.section</field>
+            <field name="type">graph</field>
+            <field name="arch" type="xml">
+                <graph orientation="horizontal" string="Leads by Section" type="bar">
+                    <field name="name"/>
+                    <field name="nbr_cases" operator="+"/>
+                </graph>
+            </field>
+        </record>
+
+               <record id="view_report_crm_lead_section_filter" model="ir.ui.view">
+            <field name="name">report.crm.lead.section.select</field>
+            <field name="model">report.crm.lead.section</field>
+            <field name="inherit_id" ref="view_report_crm_case_section_filter"/>
+            <field name="type">search</field>
+            <field name="arch" type="xml">
+                <field name="nbr_cases" position="before">
+                </field>
+            </field>
+        </record>
+
+        <record id="action_report_crm_lead_section_tree" model="ir.actions.act_window">
+            <field name="name">Leads by Section</field>
+            <field name="res_model">report.crm.lead.section</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">tree,graph</field>
+            <field name="view_id" ref="view_report_crm_lead_section_tree"/>
+            <field name="search_view_id" ref="view_report_crm_lead_section_filter"/>
+        </record>
+        <menuitem action="action_report_crm_lead_section_tree" id="menu_crm_lead_section_tree" parent="menu_crm_leads_tree"/>
   </data>
-</openerp>
\ No newline at end of file
+</openerp>
diff --git a/addons/report_crm/report_crm_opportunity.py b/addons/report_crm/report_crm_opportunity.py
new file mode 100644 (file)
index 0000000..dbd3149
--- /dev/null
@@ -0,0 +1,131 @@
+from osv import fields,osv
+import tools
+
+class report_crm_opportunity_user(osv.osv):
+    _name = "report.crm.opportunity.user"
+    _description = "Opportunity by user and section"
+    _auto = False
+    _inherit = "report.crm.case.user"
+    _columns = {
+        'probability': fields.float('Avg. Probability', readonly=True),
+        'amount_revenue': fields.float('Est.Revenue', readonly=True),
+        'amount_costs': fields.float('Est.Cost', readonly=True),
+        'amount_revenue_prob': fields.float('Est. Rev*Prob.', readonly=True),
+        'delay_close': fields.char('Delay to close', size=20, readonly=True),
+    }
+    def init(self, cr):
+        tools.drop_view_if_exists(cr, 'report_crm_opportunity_user')
+        cr.execute("""
+            create or replace view report_crm_opportunity_user as (
+                select
+                    min(c.id) as id,
+                    to_char(c.create_date, 'YYYY') as name,
+                    to_char(c.create_date, 'MM') as month,
+                    c.state,
+                    c.user_id,
+                    c.section_id,
+                    count(*) as nbr,
+                    sum(planned_revenue) as amount_revenue,
+                    sum(planned_cost) as amount_costs,
+                    sum(planned_revenue*probability)::decimal(16,2) as amount_revenue_prob,
+                    avg(probability)::decimal(16,2) as probability,
+                    to_char(avg(date_closed-c.create_date), 'DD"d" HH24:MI:SS') as delay_close
+                from
+                    crm_opportunity c
+                group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'), c.state, c.user_id,c.section_id
+            )""")
+report_crm_opportunity_user()
+
+class report_crm_opportunity_categ(osv.osv):
+    _name = "report.crm.opportunity.categ"
+    _description = "Opportunity by section and category"
+    _auto = False
+    _inherit = "report.crm.case.categ"
+    _columns = {
+        'categ_id': fields.many2one('crm.case.categ', 'Category', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]"),
+        'amount_revenue': fields.float('Est.Revenue', readonly=True),
+        'amount_costs': fields.float('Est.Cost', readonly=True),
+        'amount_revenue_prob': fields.float('Est. Rev*Prob.', readonly=True),
+        'probability': fields.float('Avg. Probability', readonly=True),
+        'delay_close': fields.char('Delay Close', size=20, readonly=True),
+    }
+    
+    def init(self, cr):
+        tools.drop_view_if_exists(cr, 'report_crm_opportunity_categ')
+        cr.execute("""
+            create or replace view report_crm_opportunity_categ as (
+                select
+                    min(c.id) as id,
+                    to_char(c.create_date, 'YYYY') as name,
+                    to_char(c.create_date, 'MM') as month,
+                    c.categ_id,
+                    c.state,
+                    c.section_id,
+                    count(*) as nbr,
+                    sum(planned_revenue) as amount_revenue,
+                    sum(planned_cost) as amount_costs,
+                    sum(planned_revenue*probability)::decimal(16,2) as amount_revenue_prob,
+                    avg(probability)::decimal(16,2) as probability,
+                    to_char(avg(date_closed-c.create_date), 'DD"d" HH24:MI:SS') as delay_close
+                from
+                    crm_opportunity c
+                group by c.categ_id,to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'), c.state,c.section_id
+            )""")
+report_crm_opportunity_categ()
+
+class report_crm_opportunity_section(osv.osv):
+    _name = "report.crm.opportunity.section"
+    _description = "Opportunity by Section"
+    _auto = False
+    _inherit = "report.crm.case.section"
+    
+    def _get_data(self, cr, uid, ids, field_name, arg, context={}):
+        res = {}
+        state_perc = 0.0
+        avg_ans = 0.0
+        
+        for case in self.browse(cr, uid, ids, context):
+            if field_name != 'avg_answers':
+                state = field_name[5:]
+                cr.execute("select count(*) from crm_opportunity where section_id =%s and state='%s'"%(case.section_id.id,state))
+                state_cases = cr.fetchone()[0]
+                perc_state = (state_cases / float(case.nbr_cases) ) * 100
+                
+                res[case.id] = perc_state
+            else:
+                cr.execute('select count(*) from crm_case_log l  where l.section_id=%s'%(case.section_id.id))
+                logs = cr.fetchone()[0]
+                
+                avg_ans = logs / case.nbr_cases
+                res[case.id] = avg_ans       
+        
+        return res
+    
+    _columns = {
+        'avg_answers': fields.function(_get_data,string='Avg. Answers', method=True,type="integer"),
+        'perc_done': fields.function(_get_data,string='%Done', method=True,type="float"),
+        'perc_cancel': fields.function(_get_data,string='%Cancel', method=True,type="float"),
+        'delay_close': fields.char('Delay to close', size=20, readonly=True),
+    }
+    _order = 'name desc, section_id'
+    def init(self, cr):
+        tools.drop_view_if_exists(cr, 'report_crm_opportunity_section')
+        cr.execute("""
+            create or replace view report_crm_opportunity_section as (
+                select
+                    min(c.id) as id,
+                    to_char(c.create_date, 'YYYY') as name,
+                    to_char(c.create_date, 'MM') as month,
+                    count(*) as nbr_cases,
+                    c.section_id as section_id,
+                    0 as avg_answers,
+                    0.0 as perc_done,
+                    0.0 as perc_cancel,
+                    to_char(avg(date_closed-c.create_date), 'DD"d" HH24:MI:SS') as delay_close
+                from
+                    crm_opportunity c
+                group by to_char(c.create_date, 'YYYY'),to_char(c.create_date, 'MM'),c.section_id
+            )""")
+report_crm_opportunity_section()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
diff --git a/addons/report_crm/report_crm_opportunity_view.xml b/addons/report_crm/report_crm_opportunity_view.xml
new file mode 100644 (file)
index 0000000..b03fd73
--- /dev/null
@@ -0,0 +1,191 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+       <!--
+       Opportunities by user and section
+       -->
+
+        <record id="view_crm_opportunity_user_tree" model="ir.ui.view">
+            <field name="name">report.crm.opportunity.user.tree</field>
+            <field name="model">report.crm.opportunity.user</field>
+            <field name="inherit_id" ref="view_crm_case_user_tree"/>
+            <field name="type">tree</field>
+            <field name="arch" type="xml">
+                <field name="nbr" position="after">
+                       <field name="delay_close"/>
+                    <field name="amount_revenue"/>
+                    <field name="amount_costs"/>
+                    <field name="amount_revenue_prob"/>
+                    <field name="probability"/>
+                </field>
+            </field>
+        </record>
+        <record id="view_crm_opportunity_user_form" model="ir.ui.view">
+            <field name="name">report.crm.opportunity.user.form</field>
+            <field name="model">report.crm.opportunity.user</field>
+            <field name="inherit_id" ref="view_crm_case_user_form"/>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+                <field name="nbr" position="after">
+                       <field name="delay_close"/>
+                    <field name="amount_revenue"/>
+                    <field name="amount_costs"/>
+                    <field name="amount_revenue_prob"/>
+                    <field name="probability"/>
+                </field>
+            </field>
+        </record>
+        
+        <record id="view_crm_opportunity_user_graph" model="ir.ui.view">
+            <field name="name">report.crm.opportunity.user.graph</field>
+            <field name="model">report.crm.opportunity.user</field>
+            <field name="type">graph</field>
+            <field name="arch" type="xml">
+                <graph orientation="horizontal" string="Opportunity by User and Section" type="bar">
+                    <field name="state"/>
+                    <field name="nbr" operator="+"/>
+                    <field group="True" name="user_id"/>
+                </graph>
+            </field>
+        </record>
+
+        <record id="view_crm_opportunity_user_filter" model="ir.ui.view">
+            <field name="name">report.crm.opportunity.user.select</field>
+            <field name="model">report.crm.opportunity.user</field>
+            <field name="inherit_id" ref="view_crm_case_user_filter"/>
+            <field name="type">search</field>
+            <field name="arch" type="xml">
+                <field name="state" position="before">
+               </field>
+            </field>
+        </record>
+        
+        <record id="action_report_crm_opportunity_user_tree" model="ir.actions.act_window">
+            <field name="name">Opportunity by User and Section</field>
+            <field name="res_model">report.crm.opportunity.user</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">tree,graph</field>
+            <field name="view_id" ref="view_crm_opportunity_user_tree"/>
+            <field name="search_view_id" ref="view_crm_opportunity_user_filter"/>
+        </record>
+        <menuitem name="Opportinities" id="menu_crm_opportunity_tree" parent="crm.next_id_52"/>
+        <menuitem action="action_report_crm_opportunity_user_tree" id="menu_crm_opportunity_user_tree" parent="menu_crm_opportunity_tree"/>
+        
+        <!-- # Opportunity by section and category of case -->
+
+        <record id="view_crm_opportunity_categ_tree" model="ir.ui.view">
+            <field name="name">report.crm.opportunity.categ.tree</field>
+            <field name="model">report.crm.opportunity.categ</field>
+            <field name="inherit_id" ref="view_crm_case_categ_tree"/>
+            <field name="type">tree</field>
+            <field name="arch" type="xml">
+                <field name="nbr" position="after">
+                    <field name="delay_close"/>
+                    <field name="amount_revenue"/>
+                    <field name="amount_costs"/>
+                    <field name="amount_revenue_prob"/>
+                    <field name="probability"/>
+                </field>
+            </field>
+        </record>
+        <record id="view_crm_opportunity_categ_form" model="ir.ui.view">
+            <field name="name">report.crm.opportunity.categ.form</field>
+            <field name="model">report.crm.opportunity.categ</field>
+            <field name="inherit_id" ref="view_crm_case_categ_form"/>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+                <field name="nbr" position="after">
+                    <field name="delay_close"/>
+                    <field name="amount_revenue"/>
+                    <field name="amount_costs"/>
+                    <field name="amount_revenue_prob"/>
+                    <field name="probability"/>
+                </field>
+            </field>
+        </record>
+
+               <record id="view_crm_opportunity_categ_graph" model="ir.ui.view">
+            <field name="name">report.crm.opportunity.categ.graph</field>
+            <field name="model">report.crm.opportunity.categ</field>
+            <field name="type">graph</field>
+            <field name="arch" type="xml">
+                <graph orientation="horizontal" string="Opportunity by Section and Categories" type="bar">
+                    <field name="state"/>
+                    <field name="nbr" operator="+"/>
+                    <field group="True" name="categ_id"/>
+                </graph>
+            </field>
+        </record>
+
+               <record id="view_crm_opportunity_categ_filter" model="ir.ui.view">
+            <field name="name">report.crm.opportunity.categ.select</field>
+            <field name="model">report.crm.opportunity.categ</field>
+                       <field name="inherit_id" ref="view_crm_case_categ_filter"/>
+            <field name="type">search</field>
+            <field name="arch" type="xml">
+                <field name="state" position="before">
+                </field>
+            </field>
+        </record>
+
+        <record id="action_report_crm_opportunity_categ_tree" model="ir.actions.act_window">
+            <field name="name">Opportunity by Categories and Section</field>
+            <field name="res_model">report.crm.opportunity.categ</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">tree,graph</field>
+            <field name="view_id" ref="view_crm_opportunity_categ_tree"/>
+            <field name="search_view_id" ref="view_crm_opportunity_categ_filter"/>
+        </record>
+        <menuitem action="action_report_crm_opportunity_categ_tree" id="menu_crm_opportunity_categ_tree" parent="menu_crm_opportunity_tree"/>
+        
+        <!-- Opportunity by Section  -->
+
+        <record id="view_report_crm_opportunity_section_tree" model="ir.ui.view">
+            <field name="name">report.crm.opportunity.section.tree</field>
+            <field name="model">report.crm.opportunity.section</field>
+            <field name="inherit_id" ref="view_report_crm_case_section_tree"/>
+            <field name="type">tree</field>
+            <field name="arch" type="xml">
+                <field name="nbr_cases" position="after">
+                       <field name="avg_answers"/>
+                       <field name="perc_done" select="2"/>
+                    <field name="perc_cancel" select="2"/>
+                    <field name="delay_close"/>
+                </field>
+            </field>
+        </record>
+
+        <record id="view_report_crm_opportunity_section_graph" model="ir.ui.view">
+            <field name="name">report.crm.opportunity.section.graph</field>
+            <field name="model">report.crm.opportunity.section</field>
+            <field name="type">graph</field>
+            <field name="arch" type="xml">
+                <graph orientation="horizontal" string="Opportunity by Section" type="bar">
+                    <field name="name"/>
+                    <field name="nbr_cases" operator="+"/>
+                </graph>
+            </field>
+        </record>
+
+               <record id="view_report_crm_opportunity_section_filter" model="ir.ui.view">
+            <field name="name">report.crm.opportunity.section.select</field>
+            <field name="model">report.crm.opportunity.section</field>
+            <field name="inherit_id" ref="view_report_crm_case_section_filter"/>
+            <field name="type">search</field>
+            <field name="arch" type="xml">
+                <field name="nbr_cases" position="before">
+                </field>
+            </field>
+        </record>
+
+        <record id="action_report_crm_opportunity_section_tree" model="ir.actions.act_window">
+            <field name="name">Opportunity by Section</field>
+            <field name="res_model">report.crm.opportunity.section</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">tree,graph</field>
+            <field name="view_id" ref="view_report_crm_opportunity_section_tree"/>
+            <field name="search_view_id" ref="view_report_crm_opportunity_section_filter"/>
+        </record>
+        <menuitem action="action_report_crm_opportunity_section_tree" id="menu_crm_opportunity_section_tree" parent="menu_crm_opportunity_tree"/>
+       </data>
+</openerp>
index 1167806..d5e0dd3 100644 (file)
             <field name="type">search</field>
             <field name="arch" type="xml">
                 <search string="Search Cases by Section">
-                   <group col="4" colspan="4">
+                   <group col="8" colspan="4">
                                <filter string="This Year" icon="terp-hr" domain="[('name','=',time.localtime()[0])]"/>
                                                <filter string="This Month" icon="terp-hr" domain="[('month','=',time.localtime()[1])]"/>
                                                <separator orientation="vertical"/>