[IMP]: crm: Major changes in crm
[odoo/odoo.git] / addons / crm / report / crm_phonecall_report.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from osv import fields,osv
23 import tools
24
25 class crm_phonecall_report(osv.osv):
26     """ Phone calls by user and section """
27
28     _name = "crm.phonecall.report"
29     _description = "Phone calls by user and section"
30     _auto = False
31 #    _inherit = "crm.case.report"
32
33     _columns = {
34         'delay_close': fields.float('Delay to close', digits=(16,2),readonly=True, group_operator="avg",help="Number of Days to close the case"),
35         'categ_id': fields.many2one('crm.case.categ', 'Category', \
36                         domain="[('section_id','=',section_id),\
37                         ('object_id.model', '=', 'crm.phonecall')]"),
38         'partner_id': fields.many2one('res.partner', 'Partner' , readonly=True),
39         'company_id': fields.many2one('res.company', 'Company', readonly=True),
40     }
41
42     def init(self, cr):
43
44         """ Phone Calls By User And Section
45             @param cr: the current row, from the database cursor,
46         """
47
48         tools.drop_view_if_exists(cr, 'crm_phonecall_report')
49         cr.execute("""
50             create or replace view crm_phonecall_report as (
51                 select
52                     min(c.id) as id,
53                     to_char(c.create_date, 'YYYY') as name,
54                     to_char(c.create_date, 'MM') as month,
55                     to_char(c.create_date, 'YYYY-MM-DD') as day,
56                     c.state,
57                     c.user_id,
58                     c.section_id,
59                     c.categ_id,
60                     c.partner_id,
61                     c.company_id,
62                     count(*) as nbr,
63                     0 as avg_answers,
64                     0.0 as perc_done,
65                     0.0 as perc_cancel,
66                     date_trunc('day',c.create_date) as create_date,
67                     avg(extract('epoch' from (c.date_closed-c.create_date)))/(3600*24) as  delay_close
68                 from
69                     crm_phonecall c
70                 group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'),\
71                      c.state, c.user_id,c.section_id, c.categ_id,c.partner_id,c.company_id
72                      ,to_char(c.create_date, 'YYYY-MM-DD'),c.create_date
73             )""")
74
75 crm_phonecall_report()
76
77 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: