2010-03-18 08:46:13 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2010-01-20 06:45:51 +00:00
|
|
|
from osv import fields,osv
|
|
|
|
import tools
|
|
|
|
|
2010-03-18 09:29:45 +00:00
|
|
|
AVAILABLE_STATES = [
|
|
|
|
('draft','Draft'),
|
|
|
|
('open','Open'),
|
|
|
|
('cancel', 'Cancelled'),
|
|
|
|
('done', 'Closed'),
|
|
|
|
('pending','Pending')
|
|
|
|
]
|
|
|
|
|
2010-03-05 13:17:53 +00:00
|
|
|
class crm_lead_report(osv.osv):
|
2010-03-18 08:46:13 +00:00
|
|
|
""" CRM Lead Report """
|
2010-03-05 13:17:53 +00:00
|
|
|
_name = "crm.lead.report"
|
2010-01-20 06:45:51 +00:00
|
|
|
_auto = False
|
2010-05-03 12:30:48 +00:00
|
|
|
# _inherit = "crm.case.report"
|
2010-03-18 08:46:13 +00:00
|
|
|
_description = "CRM Lead Report"
|
|
|
|
|
2010-01-20 06:45:51 +00:00
|
|
|
_columns = {
|
2010-04-21 10:12:25 +00:00
|
|
|
'delay_close': fields.float('Delay to close',digits=(16,2),readonly=True, group_operator="avg",help="Number of Days to close the case"),
|
2010-03-18 08:46:13 +00:00
|
|
|
'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),
|
|
|
|
'partner_id': fields.many2one('res.partner', 'Partner' , readonly=True),
|
|
|
|
'company_id': fields.many2one('res.company', 'Company', readonly=True),
|
2010-01-29 07:35:52 +00:00
|
|
|
}
|
|
|
|
def init(self, cr):
|
2010-03-18 08:46:13 +00:00
|
|
|
|
2010-03-18 11:23:49 +00:00
|
|
|
"""
|
|
|
|
CRM Lead Report
|
|
|
|
@param cr: the current row, from the database cursor
|
|
|
|
"""
|
2010-03-18 08:46:13 +00:00
|
|
|
|
2010-03-05 13:17:53 +00:00
|
|
|
tools.drop_view_if_exists(cr, 'crm_lead_report')
|
2010-01-29 07:35:52 +00:00
|
|
|
cr.execute("""
|
2010-03-05 13:17:53 +00:00
|
|
|
create or replace view crm_lead_report as (
|
2010-01-29 07:35:52 +00:00
|
|
|
select
|
|
|
|
min(c.id) as id,
|
|
|
|
to_char(c.create_date, 'YYYY') as name,
|
|
|
|
to_char(c.create_date, 'MM') as month,
|
2010-04-21 10:12:25 +00:00
|
|
|
to_char(c.create_date, 'YYYY-MM-DD') as day,
|
2010-03-18 09:29:45 +00:00
|
|
|
c.state as state,
|
2010-03-02 13:47:50 +00:00
|
|
|
c.user_id,
|
2010-01-29 07:35:52 +00:00
|
|
|
c.stage_id,
|
2010-03-05 09:20:14 +00:00
|
|
|
c.company_id,
|
2010-01-29 07:35:52 +00:00
|
|
|
c.section_id,
|
2010-03-03 07:14:05 +00:00
|
|
|
c.categ_id,
|
2010-03-05 08:19:49 +00:00
|
|
|
c.partner_id,
|
2010-01-29 07:35:52 +00:00
|
|
|
count(*) as nbr,
|
2010-03-03 08:54:24 +00:00
|
|
|
0 as avg_answers,
|
|
|
|
0.0 as perc_done,
|
|
|
|
0.0 as perc_cancel,
|
2010-04-21 10:12:25 +00:00
|
|
|
date_trunc('day',c.create_date) as create_date,
|
|
|
|
avg(extract('epoch' from (c.date_closed-c.create_date)))/(3600*24) as delay_close
|
2010-01-29 07:35:52 +00:00
|
|
|
from
|
|
|
|
crm_lead c
|
2010-03-18 08:46:13 +00:00
|
|
|
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,categ_id,c.partner_id,c.company_id
|
2010-04-21 10:12:25 +00:00
|
|
|
,c.create_date,to_char(c.create_date, 'YYYY-MM-DD')
|
2010-03-02 13:47:50 +00:00
|
|
|
)""")
|
2010-03-18 08:46:13 +00:00
|
|
|
|
2010-03-05 13:17:53 +00:00
|
|
|
crm_lead_report()
|
2010-03-18 08:46:13 +00:00
|
|
|
|
2010-03-03 07:15:21 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|