[IMP] crm/report: simplify and fix reporting views + cleanup

bzr revid: odo@openerp.com-20100629090834-e2c9p4yzxed8enjm
This commit is contained in:
Olivier Dony 2010-06-29 11:08:34 +02:00
parent 436a15ae25
commit ff27ca8040
3 changed files with 18 additions and 61 deletions

View File

@ -387,10 +387,6 @@ class crm_case(object):
attach=attach_to_send
)
self._history(cr, uid, [case], _('Send'), history=True, email=dest, details=body, email_from=src)
#if flag:
# raise osv.except_osv(_('Email!'),("Email Successfully Sent"))
#else:
# raise osv.except_osv(_('Email Fail!'),("Email is not sent successfully"))
return True
def _check(self, cr, uid, ids=False, context={}):

View File

@ -51,7 +51,7 @@ class crm_lead_report(osv.osv):
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 \
cr.execute("select count(id) 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)) * 100
@ -64,7 +64,7 @@ class crm_lead_report(osv.osv):
else:
model_name = model_name[1]
cr.execute("select count(*) from crm_case_log l, ir_model m \
cr.execute("select count(id) from crm_case_log l, ir_model m \
where l.model_id=m.id and m.model = '%s'" , model_name)
logs = cr.fetchone()[0]
@ -120,60 +120,39 @@ class crm_lead_report(osv.osv):
CRM Lead Report
@param cr: the current row, from the database cursor
"""
tools.drop_view_if_exists(cr, 'crm_lead_report')
cr.execute("""
create or replace view crm_lead_report as (
select
min(c.id) as id,
CREATE OR REPLACE VIEW crm_lead_report AS (
SELECT
id,
to_char(c.create_date, 'YYYY') as name,
to_char(c.create_date, 'MM') as month,
to_char(c.create_date, 'YYYY-MM-DD') as day,
to_char(c.create_date, 'YYYY-MM-DD') as creation_date,
to_char(c.date_open, 'YYYY-MM-DD') as opening_date,
to_char(c.date_closed, 'YYYY-mm-dd') as date_closed,
c.state as state,
c.state,
c.user_id,
c.probability,
c.stage_id,
c.type as type,
c.type,
c.company_id,
c.priority,
c.section_id,
c.categ_id,
c.partner_id,
c.planned_revenue,
(select 1) as nbr,
1 as nbr,
0 as avg_answers,
0.0 as perc_done,
0.0 as perc_cancel,
(select count(id) from mailgate_message where res_id=c.id and model='crm.lead') as email,
(SELECT count(id) FROM mailgate_message WHERE model='crm.lead' AND res_id=c.id) AS email,
date_trunc('day',c.create_date) as create_date,
avg(extract('epoch' from (c.date_closed-c.create_date)))/(3600*24) as delay_close,
avg(extract('epoch' from (c.date_deadline - c.date_closed)))/(3600*24) as delay_expected,
avg(extract('epoch' from (c.date_open-c.create_date)))/(3600*24) as delay_open
from
extract('epoch' from (c.date_closed-c.create_date))/(3600*24) as delay_close,
extract('epoch' from (c.date_deadline - c.date_closed))/(3600*24) as delay_expected,
extract('epoch' from (c.date_open-c.create_date))/(3600*24) as delay_open
FROM
crm_lead c
group by
to_char(c.create_date, 'YYYY'),
to_char(c.date_open, 'YYYY-MM-DD'),
to_char(c.date_closed, 'YYYY-mm-dd'),
to_char(c.create_date, 'MM'),
c.state,
c.user_id,
c.id,
c.section_id,
c.stage_id,
c.probability,
c.categ_id,
c.partner_id,
c.planned_revenue,
c.company_id,
c.priority,
c.type,
c.create_date,
to_char(c.create_date, 'YYYY-MM-DD')
)""")
crm_lead_report()

View File

@ -114,12 +114,11 @@ class crm_phonecall_report(osv.osv):
""" Phone Calls By User And Section
@param cr: the current row, from the database cursor,
"""
tools.drop_view_if_exists(cr, 'crm_phonecall_report')
cr.execute("""
create or replace view crm_phonecall_report as (
select
min(c.id) as id,
id,
to_char(c.create_date, 'YYYY') as name,
to_char(c.create_date, 'MM') as month,
to_char(c.create_date, 'YYYY-MM-DD') as day,
@ -135,33 +134,16 @@ class crm_phonecall_report(osv.osv):
c.duration,
c.company_id,
c.priority,
(select 1) as nbr,
1 as nbr,
0 as avg_answers,
0.0 as perc_done,
0.0 as perc_cancel,
date_trunc('day',c.create_date) as create_date,
avg(extract('epoch' from (c.date_closed-c.create_date)))/(3600*24) as delay_close,
avg(extract('epoch' from (c.date_open-c.create_date)))/(3600*24) as delay_open
extract('epoch' from (c.date_closed-c.create_date))/(3600*24) as delay_close,
extract('epoch' from (c.date_open-c.create_date))/(3600*24) as delay_open
from
crm_phonecall c
where c.categ_id in (select res_id from ir_model_data where (name = 'categ_phone1' or name ='categ_phone2'))
group by
to_char(c.create_date, 'YYYY'),
to_char(c.create_date, 'MM'),\
c.state,
c.user_id,
c.section_id,
c.categ_id,
c.partner_id,
c.company_id,
c.duration,
c.priority,
to_char(c.date_open, 'YYYY-MM-DD'),
to_char(c.date_closed, 'YYYY-mm-dd'),
c.stage_id,
to_char(c.create_date, 'YYYY-MM-DD'),
c.create_date
where c.categ_id in (select res_id from ir_model_data where (name = 'categ_phone1' or name ='categ_phone2') and model = 'crm.case.categ')
)""")
crm_phonecall_report()