[Add] report_crm: add the report crm_claim_section
authorsbh (Open ERP) <sbh@tinyerp.com>
Wed, 20 Jan 2010 08:34:41 +0000 (14:04 +0530)
committersbh (Open ERP) <sbh@tinyerp.com>
Wed, 20 Jan 2010 08:34:41 +0000 (14:04 +0530)
bzr revid: sbh@tinyerp.com-20100120083441-zulhycmvyz7ol3in

addons/report_crm/report_crm_claim.py
addons/report_crm/report_crm_claim.xml

index ac1b589..57c0df8 100644 (file)
@@ -73,5 +73,59 @@ class report_crm_claim_categ(osv.osv):
             )""")
 report_crm_claim_categ()
 
+class report_crm_claim_section(osv.osv):
+    _name = "report.crm.claim.section"
+    _description = "Claim 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_claim 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_claim_section')
+        cr.execute("""
+            create or replace view report_crm_claim_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_claim c
+                group by to_char(c.create_date, 'YYYY'),to_char(c.create_date, 'MM'),c.section_id
+            )""")
+report_crm_claim_section()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
index 0039462..4560e7b 100644 (file)
         </record>
 
         <record id="action_report_crm_claim_categ_tree" model="ir.actions.act_window">
-            <field name="name">claims by Categories and Section</field>
+            <field name="name">Claims by Categories and Section</field>
             <field name="res_model">report.crm.claim.categ</field>
             <field name="view_type">form</field>
                        <field name="view_mode">graph,tree</field>
             <field name="search_view_id" ref="view_crm_claim_categ_filter"/>
         </record>
         <menuitem action="action_report_crm_claim_categ_tree" id="menu_crm_claim_categ_tree" parent="menu_crm_claim_tree"/>
-        
+
+       <!-- Claim by Section  -->
+
+        <record id="view_report_crm_claim_section_tree" model="ir.ui.view">
+            <field name="name">report.crm.claim.section.tree</field>
+            <field name="model">report.crm.claim.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_claim_section_graph" model="ir.ui.view">
+            <field name="name">report.crm.claim.section.graph</field>
+            <field name="model">report.crm.claim.section</field>
+            <field name="type">graph</field>
+            <field name="arch" type="xml">
+                <graph orientation="horizontal" string="claims by Section" type="bar">
+                    <field name="name"/>
+                    <field name="nbr_cases" operator="+"/>
+                </graph>
+            </field>
+        </record>
+
+               <record id="view_report_crm_claim_section_filter" model="ir.ui.view">
+            <field name="name">report.crm.claim.section.select</field>
+            <field name="model">report.crm.claim.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_claim_section_tree" model="ir.actions.act_window">
+            <field name="name">Claims by Section</field>
+            <field name="res_model">report.crm.claim.section</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">tree,graph</field>
+            <field name="view_id" ref="view_report_crm_claim_section_tree"/>
+            <field name="search_view_id" ref="view_report_crm_claim_section_filter"/>
+        </record>
+        <menuitem action="action_report_crm_claim_section_tree" id="menu_crm_claim_section_tree" parent="menu_crm_claim_tree"/>        
   </data>
 </openerp>
\ No newline at end of file