Board_service : Added Report for cases by Section

bzr revid: jvo@tinyerp.com-20081213123653-3s17c9ea5zcg0pej
This commit is contained in:
Jay (Open ERP)
2008-12-13 18:06:53 +05:30
parent 4a65742d47
commit c5d1cf3a59
2 changed files with 95 additions and 0 deletions
+57
View File
@@ -106,5 +106,62 @@ class report_crm_case_categ(osv.osv):
)""")
report_crm_case_categ()
class report_crm_case_section(osv.osv):
_name = "report.crm.case.section"
_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.date('Month', 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"),
'delay_close': fields.char('Delay to close', size=20, readonly=True),
}
_order = 'name desc, section_id'
def init(self, cr):
cr.execute("""
create or replace view report_crm_case_section as (
select
min(c.id) as id,
to_char(c.create_date, 'YYYY-MM-01') as name,
c.section_id as section_id,
count(*) as nbr_cases,
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_case c
group by to_char(c.create_date, 'YYYY-MM-01'),c.section_id
)""")
report_crm_case_section()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+38
View File
@@ -155,5 +155,43 @@
<act_window domain="[('section_id', '=', active_id)]" id="act_crm_case_section_2_report_crm_case_categ" name="Monthly cases by section" res_model="report.crm.case.categ" src_model="crm.case.section"/>
<!-- Cases by Section -->
<record id="view_report_crm_case_section_tree" model="ir.ui.view">
<field name="name">report.crm.case.section.tree</field>
<field name="model">report.crm.case.section</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Cases by Section">
<field name="name"/>
<field name="section_id"/>
<field name="nbr_cases"/>
<field name="avg_answers"/>
<field name="perc_done"/>
<field name="perc_cancel"/>
<field name="delay_close"/>
</tree>
</field>
</record>
<record id="view_report_crm_case_section_graph" model="ir.ui.view">
<field name="name">report.crm.case.section.graph</field>
<field name="model">report.crm.case.section</field>
<field name="type">graph</field>
<field name="arch" type="xml">
<graph orientation="horizontal" string="Cases by Section" type="bar">
<field name="name"/>
<field name="nbr_cases" operator="+"/>
</graph>
</field>
</record>
<record id="action_report_crm_case_section_tree" model="ir.actions.act_window">
<field name="name">Cases by Section</field>
<field name="res_model">report.crm.case.section</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
</record>
</data>
</openerp>