From d7e286aa47eb78ff6b4fd01a44d1c1292bb95f9e Mon Sep 17 00:00:00 2001 From: "sbh (Open ERP)" Date: Tue, 2 Mar 2010 19:36:35 +0530 Subject: [PATCH] [IMP]report_crm: imporve the report of claim bzr revid: sbh@tinyerp.com-20100302140635-jtdmk38s46zut1s2 --- addons/report_crm/report_crm_claim.py | 224 +---------- addons/report_crm/report_crm_claim_view.xml | 394 ++------------------ 2 files changed, 42 insertions(+), 576 deletions(-) diff --git a/addons/report_crm/report_crm_claim.py b/addons/report_crm/report_crm_claim.py index 2586ad2131e..3b6df2d23cd 100644 --- a/addons/report_crm/report_crm_claim.py +++ b/addons/report_crm/report_crm_claim.py @@ -1,8 +1,8 @@ from osv import fields,osv import tools -class report_crm_claim_user(osv.osv): - _name = "report.crm.claim.user" +class report_crm_claim(osv.osv): + _name = "report.crm.claim" _description = "Claim by user and section" _auto = False _inherit = "report.crm.case.user" @@ -12,226 +12,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)""") - -report_crm_claim_section_categ_type() + 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() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/report_crm/report_crm_claim_view.xml b/addons/report_crm/report_crm_claim_view.xml index 43d57306596..387a85ffba5 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 @@ -38,7 +41,7 @@ report.crm.claim.user.graph - report.crm.claim.user + report.crm.claim graph @@ -50,8 +53,8 @@ - report.crm.claim.user.select - report.crm.claim.user + report.crm.claim.select + report.crm.claim search @@ -60,368 +63,25 @@ - + Claim by User and Section - report.crm.claim.user + 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