1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import fields,osv
28 ('cancel', 'Cancelled'),
33 class crm_lead_report(osv.osv):
34 """ CRM Lead Report """
35 _name = "crm.lead.report"
37 # _inherit = "crm.case.report"
38 _description = "CRM Lead Report"
41 'delay_close': fields.float('Delay to close',digits=(16,2),readonly=True, group_operator="avg",help="Number of Days to close the case"),
42 'categ_id': fields.many2one('crm.case.categ', 'Category',\
43 domain="[('section_id','=',section_id),\
44 ('object_id.model', '=', 'crm.lead')]" , readonly=True),
45 'stage_id': fields.many2one ('crm.case.stage', 'Stage', \
46 domain="[('section_id','=',section_id),\
47 ('object_id.model', '=', 'crm.lead')]", readonly=True),
48 'partner_id': fields.many2one('res.partner', 'Partner' , readonly=True),
49 'company_id': fields.many2one('res.company', 'Company', readonly=True),
55 @param cr: the current row, from the database cursor
58 tools.drop_view_if_exists(cr, 'crm_lead_report')
60 create or replace view crm_lead_report as (
63 to_char(c.create_date, 'YYYY') as name,
64 to_char(c.create_date, 'MM') as month,
65 to_char(c.create_date, 'YYYY-MM-DD') as day,
77 date_trunc('day',c.create_date) as create_date,
78 avg(extract('epoch' from (c.date_closed-c.create_date)))/(3600*24) as delay_close
81 group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'),\
82 c.state, c.user_id,c.section_id,c.stage_id,categ_id,c.partner_id,c.company_id
83 ,c.create_date,to_char(c.create_date, 'YYYY-MM-DD')
88 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: