From 2794713f314a0e07593e70cc9bddeba3654dff53 Mon Sep 17 00:00:00 2001 From: "sbh (Open ERP)" Date: Wed, 3 Mar 2010 10:35:09 +0530 Subject: [PATCH] [IMP] report_crm:Add the group by modfiy the view of crm_opportunity bzr revid: sbh@tinyerp.com-20100303050509-k85yjklolz83gsv2 --- addons/report_crm/report_crm_lead_view.xml | 4 +- addons/report_crm/report_crm_opportunity.py | 406 +++++++++--------- .../report_crm_opportunity_view.xml | 49 ++- addons/report_crm/report_crm_view.xml | 1 + 4 files changed, 239 insertions(+), 221 deletions(-) diff --git a/addons/report_crm/report_crm_lead_view.xml b/addons/report_crm/report_crm_lead_view.xml index 713f303d5bd..eb883facdd3 100644 --- a/addons/report_crm/report_crm_lead_view.xml +++ b/addons/report_crm/report_crm_lead_view.xml @@ -15,8 +15,8 @@ - - + + diff --git a/addons/report_crm/report_crm_opportunity.py b/addons/report_crm/report_crm_opportunity.py index 6671d72fd8b..b773f77ff54 100644 --- a/addons/report_crm/report_crm_opportunity.py +++ b/addons/report_crm/report_crm_opportunity.py @@ -1,8 +1,8 @@ from osv import fields,osv import tools -class report_crm_opportunity_user(osv.osv): - _name = "report.crm.opportunity.user" +class report_crm_opportunity(osv.osv): + _name = "report.crm.opportunity" _description = "Opportunity by user and section" _auto = False _inherit = "report.crm.case.user" @@ -11,53 +11,22 @@ class report_crm_opportunity_user(osv.osv): 'amount_revenue': fields.float('Est.Revenue', 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_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_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), + 'stage_id':fields.many2one('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), } - def init(self, cr): - tools.drop_view_if_exists(cr, 'report_crm_opportunity_categ') + tools.drop_view_if_exists(cr, 'report_crm_opportunity') cr.execute(""" - create or replace view report_crm_opportunity_categ as ( + create or replace view report_crm_opportunity 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.user_id, c.section_id, + c.categ_id, + c.stage_id, count(*) as nbr, sum(planned_revenue) as amount_revenue, sum(planned_revenue*probability)::decimal(16,2) as amount_revenue_prob, @@ -65,168 +34,203 @@ class report_crm_opportunity_categ(osv.osv): 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 + group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'), c.state, c.user_id,c.section_id,c.stage_id,c.categ_id )""") -report_crm_opportunity_categ() +report_crm_opportunity() -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() - -class report_crm_opportunity_section_type(osv.osv): - _name = "report.crm.opportunity.section.type" - _inherit = "report.crm.case.section.type" - _description = "Opportunity by section and type" - _auto = False - _columns = { - 'type_id': fields.many2one('crm.case.resource.type', 'Opportunity Type', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), - 'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), - 'amount_revenue': fields.float('Est.Revenue', readonly=True), - 'delay_close': fields.char('Delay Close', size=20, readonly=True), - } - _order = 'type_id' - - def init(self, cr): - tools.sql.drop_view_if_exists(cr, "report_crm_opportunity_section_type") - cr.execute(""" - create view report_crm_opportunity_section_type as ( - select - min(c.id) as id, - to_char(c.create_date,'YYYY') as name, - to_char(c.create_date, 'MM') as month, - c.user_id, - c.state, - c.type_id, - c.stage_id, - c.section_id, - count(*) as nbr, - sum(planned_revenue) as amount_revenue, - to_char(avg(date_closed-c.create_date), 'DD"d" HH24:MI:SS') as delay_close - from - crm_opportunity c - where c.type_id is not null - group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'), c.user_id, c.state, c.stage_id, c.type_id, c.section_id)""") - -report_crm_opportunity_section_type() - -class report_crm_opportunity_section_categ_stage(osv.osv): - _name = "report.crm.opportunity.section.categ.stage" - _inherit = "report.crm.case.section.categ.stage" - _description = "Opportunity by Section, Category and Stage" - _auto = False - _columns = { - 'categ_id': fields.many2one('crm.case.categ','Category', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), - 'stage_id':fields.many2one('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), - 'delay_close': fields.char('Delay Close', size=20, readonly=True), - } - _order = 'stage_id, categ_id' - - def init(self, cr): - tools.sql.drop_view_if_exists(cr, "report_crm_opportunity_section_categ_stage") - cr.execute(""" - create view report_crm_opportunity_section_categ_stage as ( - select - min(c.id) as id, - to_char(c.create_date,'YYYY') as name, - to_char(c.create_date, 'MM') as month, - c.user_id, - c.categ_id, - c.state, - c.stage_id, - c.section_id, - count(*) as nbr, - to_char(avg(date_closed-c.create_date), 'DD"d" HH24:MI:SS') as delay_close - from - crm_opportunity c - where c.categ_id is not null AND c.stage_id is not null - group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'),c.user_id, c.categ_id, c.state, c.stage_id, c.section_id)""") - -report_crm_opportunity_section_categ_stage() - -class report_crm_opportunity_section_categ_type(osv.osv): - _name = "report.crm.opportunity.section.categ.type" - _inherit = "report.crm.case.section.categ.type" - _description = "Opportunity by Section, Category and Type" - _auto = False - _columns = { - 'categ_id':fields.many2one('crm.case.categ', 'Category', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), - 'type_id': fields.many2one('crm.case.resource.type', 'Opportunity Type', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), - 'stage_id':fields.many2one('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), - 'delay_close': fields.char('Delay Close', size=20, readonly=True), - } - _order = 'categ_id, type_id' - - def init(self, cr): - tools.sql.drop_view_if_exists(cr, "report_crm_opportunity_section_categ_type") - cr.execute(""" - create view report_crm_opportunity_section_categ_type as ( - select - min(c.id) as id, - to_char(c.create_date, 'YYYY') as name, - to_char(c.create_date, 'MM') as month, - c.user_id, - c.categ_id, - c.type_id, - c.state, - c.stage_id, - c.section_id, - count(*) as nbr, - to_char(avg(date_closed-c.create_date), 'DD"d" HH24:MI:SS') as delay_close - from - crm_opportunity c - where c.categ_id is not null AND c.type_id is not null - group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'),c.user_id, c.categ_id, c.type_id, c.state, c.stage_id, c.section_id)""") - -report_crm_opportunity_section_categ_type() +#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_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_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() +# +#class report_crm_opportunity_section_type(osv.osv): +# _name = "report.crm.opportunity.section.type" +# _inherit = "report.crm.case.section.type" +# _description = "Opportunity by section and type" +# _auto = False +# _columns = { +# 'type_id': fields.many2one('crm.case.resource.type', 'Opportunity Type', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), +# 'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), +# 'amount_revenue': fields.float('Est.Revenue', readonly=True), +# 'delay_close': fields.char('Delay Close', size=20, readonly=True), +# } +# _order = 'type_id' +# +# def init(self, cr): +# tools.sql.drop_view_if_exists(cr, "report_crm_opportunity_section_type") +# cr.execute(""" +# create view report_crm_opportunity_section_type as ( +# select +# min(c.id) as id, +# to_char(c.create_date,'YYYY') as name, +# to_char(c.create_date, 'MM') as month, +# c.user_id, +# c.state, +# c.type_id, +# c.stage_id, +# c.section_id, +# count(*) as nbr, +# sum(planned_revenue) as amount_revenue, +# to_char(avg(date_closed-c.create_date), 'DD"d" HH24:MI:SS') as delay_close +# from +# crm_opportunity c +# where c.type_id is not null +# group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'), c.user_id, c.state, c.stage_id, c.type_id, c.section_id)""") +# +#report_crm_opportunity_section_type() +# +#class report_crm_opportunity_section_categ_stage(osv.osv): +# _name = "report.crm.opportunity.section.categ.stage" +# _inherit = "report.crm.case.section.categ.stage" +# _description = "Opportunity by Section, Category and Stage" +# _auto = False +# _columns = { +# 'categ_id': fields.many2one('crm.case.categ','Category', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), +# 'stage_id':fields.many2one('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), +# 'delay_close': fields.char('Delay Close', size=20, readonly=True), +# } +# _order = 'stage_id, categ_id' +# +# def init(self, cr): +# tools.sql.drop_view_if_exists(cr, "report_crm_opportunity_section_categ_stage") +# cr.execute(""" +# create view report_crm_opportunity_section_categ_stage as ( +# select +# min(c.id) as id, +# to_char(c.create_date,'YYYY') as name, +# to_char(c.create_date, 'MM') as month, +# c.user_id, +# c.categ_id, +# c.state, +# c.stage_id, +# c.section_id, +# count(*) as nbr, +# to_char(avg(date_closed-c.create_date), 'DD"d" HH24:MI:SS') as delay_close +# from +# crm_opportunity c +# where c.categ_id is not null AND c.stage_id is not null +# group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'),c.user_id, c.categ_id, c.state, c.stage_id, c.section_id)""") +# +#report_crm_opportunity_section_categ_stage() +# +#class report_crm_opportunity_section_categ_type(osv.osv): +# _name = "report.crm.opportunity.section.categ.type" +# _inherit = "report.crm.case.section.categ.type" +# _description = "Opportunity by Section, Category and Type" +# _auto = False +# _columns = { +# 'categ_id':fields.many2one('crm.case.categ', 'Category', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), +# 'type_id': fields.many2one('crm.case.resource.type', 'Opportunity Type', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), +# 'stage_id':fields.many2one('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.opportunity')]", readonly=True), +# 'delay_close': fields.char('Delay Close', size=20, readonly=True), +# } +# _order = 'categ_id, type_id' +# +# def init(self, cr): +# tools.sql.drop_view_if_exists(cr, "report_crm_opportunity_section_categ_type") +# cr.execute(""" +# create view report_crm_opportunity_section_categ_type as ( +# select +# min(c.id) as id, +# to_char(c.create_date, 'YYYY') as name, +# to_char(c.create_date, 'MM') as month, +# c.user_id, +# c.categ_id, +# c.type_id, +# c.state, +# c.stage_id, +# c.section_id, +# count(*) as nbr, +# to_char(avg(date_closed-c.create_date), 'DD"d" HH24:MI:SS') as delay_close +# from +# crm_opportunity c +# where c.categ_id is not null AND c.type_id is not null +# group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'),c.user_id, c.categ_id, c.type_id, c.state, c.stage_id, c.section_id)""") +# +#report_crm_opportunity_section_categ_type() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/report_crm/report_crm_opportunity_view.xml b/addons/report_crm/report_crm_opportunity_view.xml index 17310cfd0aa..ce786cec554 100644 --- a/addons/report_crm/report_crm_opportunity_view.xml +++ b/addons/report_crm/report_crm_opportunity_view.xml @@ -5,24 +5,29 @@ Opportunities by user and section --> - - report.crm.opportunity.user.tree - report.crm.opportunity.user - + + report.crm.opportunity.tree + report.crm.opportunity tree - + + + + - - - + + + + + + - report.crm.opportunity.user.form - report.crm.opportunity.user + report.crm.opportunity.form + report.crm.opportunity form @@ -37,8 +42,8 @@ - report.crm.opportunity.user.graph - report.crm.opportunity.user + report.crm.opportunity.graph + report.crm.opportunity graph @@ -51,7 +56,7 @@ report.crm.opportunity.user.select - report.crm.opportunity.user + report.crm.opportunity search @@ -60,18 +65,25 @@ - + Opportunity by User and Section - report.crm.opportunity.user + report.crm.opportunity form graph,tree + + + tree + + + - + - + + Opportunity by Section report.crm.opportunity.section.tree @@ -422,5 +434,6 @@ + --> diff --git a/addons/report_crm/report_crm_view.xml b/addons/report_crm/report_crm_view.xml index 49a46162db6..c5189871ea8 100644 --- a/addons/report_crm/report_crm_view.xml +++ b/addons/report_crm/report_crm_view.xml @@ -77,6 +77,7 @@ +