[REM]: crm: Moved helpdesk from crm
[odoo/odoo.git] / addons / crm_helpdesk / report / crm_helpdesk_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
26 class crm_helpdesk_report(osv.osv):
27     """ Helpdesk report after Sales Services """
28
29     _name = "crm.helpdesk.report"
30     _description = "Helpdesk report after Sales Services"
31     _auto = False
32     _inherit = "crm.case.report"
33
34     _columns = {
35         'delay_close': fields.char('Delay to close', size=20, readonly=True),
36         'partner_id': fields.many2one('res.partner', 'Partner' , readonly=True),
37         'company_id': fields.many2one('res.company', 'Company', readonly=True),
38         'date_deadline': fields.date('Deadline'),
39         'priority': fields.selection([('5', 'Lowest'), ('4', 'Low'), \
40                     ('3', 'Normal'), ('2', 'High'), ('1', 'Highest')], 'Priority'),
41     }
42
43     def init(self, cr):
44
45         """
46             Display Deadline ,Responsible user, partner ,Department
47             @param cr: the current row, from the database cursor
48         """
49
50         tools.drop_view_if_exists(cr, 'crm_helpdesk_report')
51         cr.execute("""
52             create or replace view crm_helpdesk_report as (
53                 select
54                     min(c.id) as id,
55                     to_char(c.create_date, 'YYYY') as name,
56                     to_char(c.create_date, 'MM') as month,
57                     c.state,
58                     c.user_id,
59                     c.section_id,
60                     c.partner_id,
61                     c.company_id,
62                     c.priority,
63                     c.date_deadline,
64                     count(*) as nbr,
65                     0 as avg_answers,
66                     0.0 as perc_done,
67                     0.0 as perc_cancel,
68                     to_char(avg(date_closed-c.create_date), 'DD"d" HH24:MI:SS') as delay_close
69                 from
70                     crm_helpdesk c
71                 group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'),\
72                      c.state, c.user_id,c.section_id,c.priority,\
73                       c.partner_id,c.company_id,c.date_deadline
74             )""")
75
76 crm_helpdesk_report()
77
78 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: