diff --git a/addons/report_crm/__terp__.py b/addons/report_crm/__terp__.py index 9d9dae37390..6e0870fa24e 100644 --- a/addons/report_crm/__terp__.py +++ b/addons/report_crm/__terp__.py @@ -30,7 +30,7 @@ 'website': 'http://www.openerp.com', 'depends': ['crm'], 'init_xml': [], - 'update_xml': ['security/ir.model.access.csv', + 'update_xml': [#'security/ir.model.access.csv', 'report_crm_view.xml', 'report_crm_lead_view.xml', 'report_crm_claim_view.xml', diff --git a/addons/report_crm/report_crm_claim.py b/addons/report_crm/report_crm_claim.py index 2586ad2131e..7501e27ab37 100644 --- a/addons/report_crm/report_crm_claim.py +++ b/addons/report_crm/report_crm_claim.py @@ -1,9 +1,8 @@ from osv import fields,osv import tools -class report_crm_claim_user(osv.osv): - _name = "report.crm.claim.user" - _description = "Claim by user and section" +class report_crm_claim(osv.osv): + _name = "report.crm.claim" _auto = False _inherit = "report.crm.case.user" _columns = { @@ -12,226 +11,32 @@ class report_crm_claim_user(osv.osv): '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_claim_user') - cr.execute(""" - create or replace view report_crm_claim_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_claim 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_claim_user() - -class report_crm_claim_categ(osv.osv): - _name = "report.crm.claim.categ" - _description = "Claim 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.claim')]"), - '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_claim_categ') - cr.execute(""" - create or replace view report_crm_claim_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_claim 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_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() - -class report_crm_claim_section_type(osv.osv): - _name = "report.crm.claim.section.type" - _inherit = "report.crm.case.section.type" - _description = "Claims by section and type" - _auto = False - _columns = { - 'type_id': fields.many2one('crm.case.resource.type', 'Claim Type', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.claim')]", readonly=True), 'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.claim')]", readonly=True), - 'amount_revenue': fields.float('Est.Revenue', readonly=True), - 'delay_close': fields.char('Delay Close', size=20, readonly=True), + 'categ_id': fields.many2one('crm.case.categ', 'Category', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.claim')]"), } - _order = 'type_id' - def init(self, cr): - tools.sql.drop_view_if_exists(cr, "report_crm_claim_section_type") + tools.drop_view_if_exists(cr, 'report_crm_claim') cr.execute(""" - create view report_crm_claim_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_claim 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_claim_section_type() - -class report_crm_claim_section_categ_stage(osv.osv): - _name = "report.crm.claim.section.categ.stage" - _inherit = "report.crm.case.section.categ.stage" - _description = "Claims 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.claim')]", readonly=True), - 'stage_id':fields.many2one('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.claim')]", 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_claim_section_categ_stage") - cr.execute(""" - create view report_crm_claim_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_claim 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_claim_section_categ_stage() - -class report_crm_claim_section_categ_type(osv.osv): - _name = "report.crm.claim.section.categ.type" - _inherit = "report.crm.case.section.categ.type" - _description = "Claims 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.claim')]", readonly=True), - 'type_id': fields.many2one('crm.case.resource.type', 'Claim Type', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.claim')]", readonly=True), - 'stage_id':fields.many2one('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.claim')]", 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_claim_section_categ_type") - cr.execute(""" - create view report_crm_claim_section_categ_type as ( + create or replace view report_crm_claim 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.user_id, c.section_id, + c.stage_id, + c.categ_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_claim 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)""") + 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_claim() -report_crm_claim_section_categ_type() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/report_crm/report_crm_claim_view.xml b/addons/report_crm/report_crm_claim_view.xml index 43d57306596..b0553e64f09 100644 --- a/addons/report_crm/report_crm_claim_view.xml +++ b/addons/report_crm/report_crm_claim_view.xml @@ -5,24 +5,27 @@ Claim by user and section --> - - report.crm.claim.user.tree - report.crm.claim.user - + + report.crm.claim.tree + report.crm.claim tree - + + + + - - + + + - - report.crm.claim.user.form - report.crm.claim.user + + report.crm.claim.form + report.crm.claim form @@ -36,12 +39,12 @@ - - report.crm.claim.user.graph - report.crm.claim.user + + report.crm.claim.graph + report.crm.claim graph - + @@ -49,9 +52,9 @@ - - report.crm.claim.user.select - report.crm.claim.user + + report.crm.claim.select + report.crm.claim search @@ -60,368 +63,24 @@ - - Claim by User and Section - report.crm.claim.user + + Claim + report.crm.claim form graph,tree - - + + - - + + + + tree + + + + - + - - report.crm.claim.categ.tree - report.crm.claim.categ - - tree - - - - - - - - - - - - report.crm.claim.categ.form - report.crm.claim.categ - - form - - - - - - - - - - - - - report.crm.claim.categ.graph - report.crm.claim.categ - graph - - - - - - - - - - - report.crm.claim.categ.select - report.crm.claim.categ - - search - - - - - - - - Claims by Categories and Section - report.crm.claim.categ - form - graph,tree - - - - - - - - - report.crm.claim.section.tree - report.crm.claim.section - - tree - - - - - - - - - - - - report.crm.claim.section.graph - report.crm.claim.section - graph - - - - - - - - - - report.crm.claim.section.select - report.crm.claim.section - - search - - - - - - - - Claims by Section - report.crm.claim.section - form - graph,tree - - - - - - # - # Claims by section and type - # - - - CRM Report - Sections and Type(Tree) - report.crm.claim.section.type - - tree - - - - - - - - - - - CRM Report - Sections and Type(Form) - report.crm.claim.section.type - - form - - - - - - - - - - - - CRM Report - Sections and Type(Graph) - report.crm.claim.section.type - graph - - - - - - - - - - CRM Report - Sections and Type(Select) - report.crm.claim.section.type - - search - - - - - - - - - report.crm.claim.section.type - Claims by section and type - form - graph,tree - - - - - graph - - - - - - tree - - - - - - # - # Claims by section, category and stage - # - - - CRM Report - Section, Category and Stage(Tree) - report.crm.claim.section.categ.stage - - tree - - - - - - - - - - CRM Report - Section, Category and Stage(Form) - report.crm.claim.section.categ.stage - - form - - - - - - - - - - - CRM Report - Section, Category and Stage(Select) - report.crm.claim.section.categ.stage - graph - - - - - - - - - - CRM Report - Section, Category and Stage(Select) - report.crm.claim.section.categ.stage - - search - - - - - - - - - - report.crm.claim.section.categ.stage - Claims by section, category and stage - form - graph,tree - - - - - graph - - - - - - tree - - - - - - # - # Claims by section, category and type - # - - - CRM Report - Section, Category and Type(Tree) - report.crm.claim.section.categ.type - - tree - - - - - - - - - - - CRM Report - Section, Category and Type(Form) - report.crm.claim.section.categ.type - - form - - - - - - - - - - - - CRM Report - Section, Category and Type(Select) - report.crm.claim.section.categ.type - graph - - - - - - - - - - CRM Report - Section, Category and Type(Select) - report.crm.claim.section.categ.type - - search - - - - - - - - - - - report.crm.claim.section.categ.type - Claims by section, category and type - form - graph,tree - - - - - graph - - - - - - tree - - - - - - \ No newline at end of file + diff --git a/addons/report_crm/report_crm_lead.py b/addons/report_crm/report_crm_lead.py index 479b93445c4..3f57835bf6c 100644 --- a/addons/report_crm/report_crm_lead.py +++ b/addons/report_crm/report_crm_lead.py @@ -1,273 +1,31 @@ from osv import fields,osv import tools -class report_crm_lead_user(osv.osv): - _name = "report.crm.lead.user" - _description = "Leads by user and section" +class report_crm_lead(osv.osv): + _name = "report.crm.lead" _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_lead_user') - cr.execute(""" - create or replace view report_crm_lead_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_lead 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_lead_user() - -class report_crm_lead_categ(osv.osv): - _name = "report.crm.lead.categ" - _description = "Leads 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.lead')]"), - '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_lead_categ') - cr.execute(""" - create or replace view report_crm_lead_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_lead 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_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() - -class report_crm_lead_section_stage(osv.osv): - _name = "report.crm.lead.section.stage" - _description = "Leads by section and stage" - _auto = False - _inherit = "report.crm.case.section.stage" - _columns = { - 'categ_id': fields.many2one('crm.case.categ', 'Category', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.lead')]", readonly=True), 'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.lead')]", readonly=True), - 'amount_revenue': fields.float('Est.Revenue', readonly=True), - 'delay_close': fields.char('Delay Close', size=20, readonly=True), - } - _order = 'stage_id, section_id' - - def init(self, cr): - tools.sql.drop_view_if_exists(cr, "report_crm_lead_section_stage") - cr.execute(""" - create view report_crm_lead_section_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.state, - c.stage_id, - c.section_id, - c.categ_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_lead c - where c.stage_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.categ_id, c.section_id)""") - -report_crm_lead_section_stage() - -class report_crm_lead_section_type(osv.osv): - _name = "report.crm.lead.section.type" - _inherit = "report.crm.case.section.type" - _description = "Leads by section and type" - _auto = False - _columns = { - 'type_id': fields.many2one('crm.case.resource.type', 'Lead Type', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.lead')]", readonly=True), - 'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.lead')]", 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_lead_section_type") + tools.drop_view_if_exists(cr, 'report_crm_lead') cr.execute(""" - create view report_crm_lead_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_lead 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_lead_section_type() - -class report_crm_lead_section_categ_stage(osv.osv): - _name = "report.crm.lead.section.categ.stage" - _inherit = "report.crm.case.section.categ.stage" - _description = "Leads 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.lead')]", readonly=True), - 'stage_id':fields.many2one('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.lead')]", 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_lead_section_categ_stage") - cr.execute(""" - create view report_crm_lead_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_lead 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_lead_section_categ_stage() - -class report_crm_lead_section_categ_type(osv.osv): - _name = "report.crm.lead.section.categ.type" - _inherit = "report.crm.case.section.categ.type" - _description = "Leads 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.lead')]", readonly=True), - 'type_id': fields.many2one('crm.case.resource.type', 'Lead Type', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.lead')]", readonly=True), - 'stage_id':fields.many2one('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.lead')]", 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_lead_section_categ_type") - cr.execute(""" - create view report_crm_lead_section_categ_type as ( + create or replace view report_crm_lead 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.user_id, 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_lead 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_lead_section_categ_type() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file + 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 + )""") +report_crm_lead() +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/report_crm/report_crm_lead_view.xml b/addons/report_crm/report_crm_lead_view.xml index 8dbec663dd2..e7ed028a222 100644 --- a/addons/report_crm/report_crm_lead_view.xml +++ b/addons/report_crm/report_crm_lead_view.xml @@ -5,43 +5,39 @@ Leads by user and section --> - - report.crm.lead.user.tree - report.crm.lead.user - + + report.crm.lead.tree + report.crm.lead tree - - - - - - - + + + + + + + - - report.crm.lead.user.form - report.crm.lead.user + + report.crm.lead.form + report.crm.lead form - - - - + - - report.crm.lead.user.graph - report.crm.lead.user + + report.crm.lead.graph + report.crm.lead graph - + @@ -49,437 +45,36 @@ - - report.crm.lead.user.select - report.crm.lead.user + + report.crm.lead.select + report.crm.lead search - - + + + - - - Leads by User and Section - report.crm.lead.user + + + + Leads + report.crm.lead form graph,tree - - + + - - - - - - - report.crm.lead.categ.tree - report.crm.lead.categ - - tree - - - - - - - - - - - - report.crm.lead.categ.form - report.crm.lead.categ - - form - - - - - - - - - - - - - report.crm.lead.categ.graph - report.crm.lead.categ - graph - - - - - - - - - - - report.crm.lead.categ.select - report.crm.lead.categ - - search - - - - - - - - Leads by Categories and Section - report.crm.lead.categ - form - graph,tree - - - - - - - - - report.crm.lead.section.tree - report.crm.lead.section - - tree - - - - - - - - - - - - report.crm.lead.section.graph - report.crm.lead.section - graph - - - - - - - - - - report.crm.lead.section.select - report.crm.lead.section - - search - - - - - - - - Leads by Section - report.crm.lead.section - form - graph,tree - - - - - - - - - Leads Report - Sections and Stage(Tree) - report.crm.lead.section.stage - - tree - - - - - - - - - - - Leads Report - Sections and Stage(Form) - report.crm.lead.section.stage - form - - - - - - - - - - - Leads Report - Sections and Stage(Graph) - report.crm.lead.section.stage - graph - - - - - - - - - - Leads Report - Sections and Stage(Select) - report.crm.lead.section.stage - search - - - - - - - - report.crm.lead.section.stage - form - graph,tree - - - - - # - # Leads by section and type - # - - - CRM Report - Sections and Type(Tree) - report.crm.lead.section.type - - tree - - - - - - - - - - - CRM Report - Sections and Type(Form) - report.crm.lead.section.type - - form - - - - - - - - - - - - CRM Report - Sections and Type(Graph) - report.crm.lead.section.type - graph - - - - - - - - - - CRM Report - Sections and Type(Select) - report.crm.lead.section.type - - search - - - - - - - - - report.crm.lead.section.type - Leads by section and type - form - graph,tree - - - - - graph - - - - - - tree - - - - - - # - # Leads by section, category and stage - # - - - CRM Report - Section, Category and Stage(Tree) - report.crm.lead.section.categ.stage - - tree - - - - - - - - - - CRM Report - Section, Category and Stage(Form) - report.crm.lead.section.categ.stage - - form - - - - - - - - - - - CRM Report - Section, Category and Stage(Select) - report.crm.lead.section.categ.stage - graph - - - - - - - - - - CRM Report - Section, Category and Stage(Select) - report.crm.lead.section.categ.stage - - search - - - - - - - - - - report.crm.lead.section.categ.stage - Leads by section, category and stage - form - graph,tree - - - - - graph - - - - - - tree - - - - - - # - # Leads by section, category and type - # - - - CRM Report - Section, Category and Type(Tree) - report.crm.lead.section.categ.type - - tree - - - - - - - - - - - CRM Report - Section, Category and Type(Form) - report.crm.lead.section.categ.type - - form - - - - - - - - - - - - CRM Report - Section, Category and Type(Select) - report.crm.lead.section.categ.type - graph - - - - - - - - - - CRM Report - Section, Category and Type(Select) - report.crm.lead.section.categ.type - - search - - - - - - - - - - - report.crm.lead.section.categ.type - Leads by section, category and type - form - graph,tree - - - - - graph - - - - - - tree - - - - + + + + tree + + + + + + diff --git a/addons/report_crm/report_crm_opportunity.py b/addons/report_crm/report_crm_opportunity.py index 6671d72fd8b..501b4c2855d 100644 --- a/addons/report_crm/report_crm_opportunity.py +++ b/addons/report_crm/report_crm_opportunity.py @@ -1,9 +1,8 @@ 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" +class report_crm_opportunity(osv.osv): + _name = "report.crm.opportunity" _auto = False _inherit = "report.crm.case.user" _columns = { @@ -11,53 +10,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 +33,7 @@ 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() - -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() +report_crm_opportunity() # 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..293beb8f3d9 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 @@ -36,12 +41,12 @@ - - report.crm.opportunity.user.graph - report.crm.opportunity.user + + report.crm.opportunity.graph + report.crm.opportunity graph - + @@ -49,9 +54,9 @@ - - report.crm.opportunity.user.select - report.crm.opportunity.user + + report.crm.opportunity.select + report.crm.opportunity search @@ -60,367 +65,20 @@ - - Opportunity by User and Section - report.crm.opportunity.user + + Opportunity + report.crm.opportunity form graph,tree - - + + - - - - - - - report.crm.opportunity.categ.tree - report.crm.opportunity.categ - - tree - - - - - - - - - - - - report.crm.opportunity.categ.form - report.crm.opportunity.categ - - form - - - - - - - - - - - - - report.crm.opportunity.categ.graph - report.crm.opportunity.categ - graph - - - - - - - - - - - report.crm.opportunity.categ.select - report.crm.opportunity.categ - - search - - - - - - - - Opportunity by Categories and Section - report.crm.opportunity.categ - form - graph,tree - - - - - - - - - report.crm.opportunity.section.tree - report.crm.opportunity.section - - tree - - - - - - - - - - - - report.crm.opportunity.section.graph - report.crm.opportunity.section - graph - - - - - - - - - - report.crm.opportunity.section.select - report.crm.opportunity.section - - search - - - - - - - - Opportunity by Section - report.crm.opportunity.section - form - graph,tree - - - - - - # - # Opportunity by section and type - # - - - CRM Report - Sections and Type(Tree) - report.crm.opportunity.section.type - - tree - - - - - - - - - - - CRM Report - Sections and Type(Form) - report.crm.opportunity.section.type - - form - - - - - - - - - - - - CRM Report - Sections and Type(Graph) - report.crm.opportunity.section.type - graph - - - - - - - - - - CRM Report - Sections and Type(Select) - report.crm.opportunity.section.type - - search - - - - - - - - - report.crm.opportunity.section.type - Opportunity by section and type - form - graph,tree - - - - - graph - - - - - - tree - - - - - - # - # Opportunity by section, category and stage - # - - - CRM Report - Section, Category and Stage(Tree) - report.crm.opportunity.section.categ.stage - - tree - - - - - - - - - - CRM Report - Section, Category and Stage(Form) - report.crm.opportunity.section.categ.stage - - form - - - - - - - - - - - CRM Report - Section, Category and Stage(Select) - report.crm.opportunity.section.categ.stage - graph - - - - - - - - - - CRM Report - Section, Category and Stage(Select) - report.crm.opportunity.section.categ.stage - - search - - - - - - - - - - report.crm.opportunity.section.categ.stage - Opportunity by section, category and stage - form - graph,tree - - - - - graph - - - - - - tree - - - - - - # - # opportunitys by section, category and type - # - - - CRM Report - Section, Category and Type(Tree) - report.crm.opportunity.section.categ.type - - tree - - - - - - - - - - - CRM Report - Section, Category and Type(Form) - report.crm.opportunity.section.categ.type - - form - - - - - - - - - - - - CRM Report - Section, Category and Type(Select) - report.crm.opportunity.section.categ.type - graph - - - - - - - - - - CRM Report - Section, Category and Type(Select) - report.crm.opportunity.section.categ.type - - search - - - - - - - - - - - report.crm.opportunity.section.categ.type - Opportunity by section, category and type - form - graph,tree - - - - - graph - - - - - - tree - - - - + + + tree + + + + diff --git a/addons/report_crm/report_crm_view.xml b/addons/report_crm/report_crm_view.xml index 7b46928cb6b..c5189871ea8 100644 --- a/addons/report_crm/report_crm_view.xml +++ b/addons/report_crm/report_crm_view.xml @@ -56,11 +56,13 @@ search - + + + @@ -69,6 +71,16 @@ + + + + + + + + + +