From 2a5ebcdb4dbfe503a5935d150067986da2ae9ecf Mon Sep 17 00:00:00 2001 From: "sbh (Open ERP)" Date: Wed, 20 Jan 2010 14:22:45 +0530 Subject: [PATCH] [Add] report_crm: add the report_crm_fundraising bzr revid: sbh@tinyerp.com-20100120085245-a597tedeblhrb3yp --- addons/report_crm/__init__.py | 1 + addons/report_crm/__terp__.py | 5 +- ...rm_claim.xml => report_crm_claim_view.xml} | 0 addons/report_crm/report_crm_fundraising.py | 131 ++++++++++++ .../report_crm_fundraising_view.xml | 191 ++++++++++++++++++ 5 files changed, 326 insertions(+), 2 deletions(-) rename addons/report_crm/{report_crm_claim.xml => report_crm_claim_view.xml} (100%) create mode 100644 addons/report_crm/report_crm_fundraising.py create mode 100644 addons/report_crm/report_crm_fundraising_view.xml diff --git a/addons/report_crm/__init__.py b/addons/report_crm/__init__.py index 7697ecb2cc8..7a050fae5a7 100644 --- a/addons/report_crm/__init__.py +++ b/addons/report_crm/__init__.py @@ -23,6 +23,7 @@ import report_crm import report_crm_lead import report_crm_claim import report_crm_opportunity +import report_crm_fundraising import report_crm_phonecall # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/report_crm/__terp__.py b/addons/report_crm/__terp__.py index f50660ce8bb..9d9dae37390 100644 --- a/addons/report_crm/__terp__.py +++ b/addons/report_crm/__terp__.py @@ -33,9 +33,10 @@ 'update_xml': ['security/ir.model.access.csv', 'report_crm_view.xml', 'report_crm_lead_view.xml', - 'report_crm_claim.xml', + 'report_crm_claim_view.xml', 'report_crm_opportunity_view.xml', - 'report_crm_phonecall_view.xml', + 'report_crm_phonecall_view.xml', + 'report_crm_fundraising_view.xml' ], 'demo_xml': [], 'installable': True, #TODO : After fixed problems , set True diff --git a/addons/report_crm/report_crm_claim.xml b/addons/report_crm/report_crm_claim_view.xml similarity index 100% rename from addons/report_crm/report_crm_claim.xml rename to addons/report_crm/report_crm_claim_view.xml diff --git a/addons/report_crm/report_crm_fundraising.py b/addons/report_crm/report_crm_fundraising.py new file mode 100644 index 00000000000..4ee8911a776 --- /dev/null +++ b/addons/report_crm/report_crm_fundraising.py @@ -0,0 +1,131 @@ +from osv import fields,osv +import tools + +class report_crm_fundraising_user(osv.osv): + _name = "report.crm.fundraising.user" + _description = "Fundraising 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_fundraising_user') + cr.execute(""" + create or replace view report_crm_fundraising_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_fundraising 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_fundraising_user() + +class report_crm_fundraising_categ(osv.osv): + _name = "report.crm.fundraising.categ" + _description = "Fundraising 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.fundraising')]"), + '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_fundraising_categ') + cr.execute(""" + create or replace view report_crm_fundraising_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_fundraising 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_fundraising_categ() + +class report_crm_fundraising_section(osv.osv): + _name = "report.crm.fundraising.section" + _description = "Fundraising 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_fundraising 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_fundraising_section') + cr.execute(""" + create or replace view report_crm_fundraising_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_fundraising c + group by to_char(c.create_date, 'YYYY'),to_char(c.create_date, 'MM'),c.section_id + )""") +report_crm_fundraising_section() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/report_crm/report_crm_fundraising_view.xml b/addons/report_crm/report_crm_fundraising_view.xml new file mode 100644 index 00000000000..7b8165c67fe --- /dev/null +++ b/addons/report_crm/report_crm_fundraising_view.xml @@ -0,0 +1,191 @@ + + + + + + + report.crm.fundraising.user.tree + report.crm.fundraising.user + + tree + + + + + + + + + + + + report.crm.fundraising.user.form + report.crm.fundraising.user + + form + + + + + + + + + + + + + report.crm.fundraising.user.graph + report.crm.fundraising.user + graph + + + + + + + + + + + report.crm.fundraising.user.select + report.crm.fundraising.user + + search + + + + + + + + fundraising by User and Section + report.crm.fundraising.user + form + tree,graph + + + + + + + + + + report.crm.fundraising.categ.tree + report.crm.fundraising.categ + + tree + + + + + + + + + + + + report.crm.fundraising.categ.form + report.crm.fundraising.categ + + form + + + + + + + + + + + + + report.crm.fundraising.categ.graph + report.crm.fundraising.categ + graph + + + + + + + + + + + report.crm.fundraising.categ.select + report.crm.fundraising.categ + + search + + + + + + + + Fundraising by Categories and Section + report.crm.fundraising.categ + form + tree,graph + + + + + + + + + report.crm.fundraising.section.tree + report.crm.fundraising.section + + tree + + + + + + + + + + + + report.crm.fundraising.section.graph + report.crm.fundraising.section + graph + + + + + + + + + + report.crm.fundraising.section.select + report.crm.fundraising.section + + search + + + + + + + + Fundraising by Section + report.crm.fundraising.section + form + tree,graph + + + + + +