[Add] crm_hr: add the code of report_crm_job_categ and report_crm_job_user report

bzr revid: sbh@tinyerp.com-20100120124602-s00uip3i5nsiszzq
This commit is contained in:
sbh (Open ERP)
2010-01-20 18:16:02 +05:30
parent 27fd523f75
commit 3508bcd0bc
2 changed files with 90 additions and 58 deletions
+90
View File
@@ -1,6 +1,41 @@
from osv import fields,osv
import tools
class report_crm_job_user(osv.osv):
_name = "report.crm.job.user"
_description = "Job 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_job_user')
cr.execute("""
create or replace view report_crm_job_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_job 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_job_user()
class report_crm_job_categ(osv.osv):
_name = "report.crm.job.categ"
_description = "Jobs by section and category"
@@ -38,4 +73,59 @@ class report_crm_job_categ(osv.osv):
)""")
report_crm_job_categ()
class report_crm_job_section(osv.osv):
_name = "report.crm.job.section"
_description = "job 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_job 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_job_section')
cr.execute("""
create or replace view report_crm_job_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_job c
group by to_char(c.create_date, 'YYYY'),to_char(c.create_date, 'MM'),c.section_id
)""")
report_crm_job_section()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-58
View File
@@ -188,63 +188,5 @@
</record>
<menuitem action="action_report_crm_job_section_tree" id="menu_crm_job_section_tree" parent="menu_crm_jobs_tree"/>
<!-- Cases by section and stage -->
<record model="ir.ui.view" id="view_crm_job_section_stage_tree">
<field name="name">Jobs Report - Sections and Stage(Tree)</field>
<field name="model">report.crm.job.section.stage</field>
<field name="inherit_id" ref="report_crm.view_crm_case_section_stage_tree"/>
<field name="type">tree</field>
<field name="arch" type="xml">
<field name="nbr" position="after">
<field name="categ_id"/>
<field name="stage_id" select="2"/>
<field name="amount_revenue" select="2"/>
<field name="delay_close"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="view_crm_job_section_stage_form">
<field name="name">jobs Report - Sections and Stage(Form)</field>
<field name="model">report.crm.job.section.stage</field>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="nbr" position="after">
<field name="categ_id"/>
<field name="stage_id" select="2"/>
<field name="amount_revenue" select="2"/>
<field name="delay_close"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="view_crm_job_section_stage_graph">
<field name="name">Jobs Report - Sections and Stage(Graph)</field>
<field name="model">report.crm.job.section.stage</field>
<field name="type">graph</field>
<field name="arch" type="xml">
<graph string="jobs by Section and Stage" type="bar" orientation="horizontal">
<field name="stage_id"/>
<field name="amount_revenue" operator="+"/>
<field name="section_id" group="True"/>
</graph>
</field>
</record>
<record id="view_crm_job_section_stage_filter" model="ir.ui.view">
<field name="name">Jobs Report - Sections and Stage(Select)</field>
<field name="model">report.crm.job.section.stage</field>
<field name="type">search</field>
<field name="arch" type="xml">
<field name="state" position="before">
</field>
</field>
</record>
<record model="ir.actions.act_window" id="action_report_crm_job_section_stage_tree">
<field name="res_model">report.crm.job.section.stage</field>
<field name="view_type">form</field>
<field name="view_mode">graph,tree</field>
<field name="view_id" ref="view_crm_job_section_stage_tree"/>
<field name="search_view_id" ref="view_crm_job_section_stage_filter"/>
</record>
</data>
</openerp>