[FIX] remove unused fields from report objects.
[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 AVAILABLE_STATES = [
27     ('draft','Draft'),
28     ('open','Open'),
29     ('cancel', 'Cancelled'),
30     ('done', 'Closed'),
31     ('pending','Pending')
32 ]
33
34 class crm_helpdesk_report(osv.osv):
35     """ Helpdesk report after Sales Services """
36
37     _name = "crm.helpdesk.report"
38     _description = "Helpdesk report after Sales Services"
39     _auto = False
40
41     _columns = {
42         'name': fields.char('Year', size=64, required=False, readonly=True),
43         'user_id':fields.many2one('res.users', 'User', readonly=True),
44         'section_id':fields.many2one('crm.case.section', 'Section', readonly=True),
45         'nbr': fields.integer('# of Cases', readonly=True),
46         'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
47         'month':fields.selection([('01', 'January'), ('02', 'February'), \
48                                   ('03', 'March'), ('04', 'April'),\
49                                   ('05', 'May'), ('06', 'June'), \
50                                   ('07', 'July'), ('08', 'August'),\
51                                   ('09', 'September'), ('10', 'October'),\
52                                   ('11', 'November'), ('12', 'December')], 'Month', readonly=True),
53         'delay_close': fields.char('Delay to close', size=20, readonly=True),
54         'partner_id': fields.many2one('res.partner', 'Partner' , readonly=True),
55         'company_id': fields.many2one('res.company', 'Company', readonly=True),
56         'date_deadline': fields.date('Deadline'),
57         'priority': fields.selection([('5', 'Lowest'), ('4', 'Low'), \
58                     ('3', 'Normal'), ('2', 'High'), ('1', 'Highest')], 'Priority'),
59     }
60
61     def init(self, cr):
62
63         """
64             Display Deadline ,Responsible user, partner ,Department
65             @param cr: the current row, from the database cursor
66         """
67
68         tools.drop_view_if_exists(cr, 'crm_helpdesk_report')
69         cr.execute("""
70             create or replace view crm_helpdesk_report as (
71                 select
72                     min(c.id) as id,
73                     to_char(c.create_date, 'YYYY') as name,
74                     to_char(c.create_date, 'MM') as month,
75                     c.state,
76                     c.user_id,
77                     c.section_id,
78                     c.partner_id,
79                     c.company_id,
80                     c.priority,
81                     c.date_deadline,
82                     count(*) as nbr,
83                     to_char(avg(date_closed-c.create_date), 'DD"d" HH24:MI:SS') as delay_close
84                 from
85                     crm_helpdesk c
86                 group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'),\
87                      c.state, c.user_id,c.section_id,c.priority,\
88                       c.partner_id,c.company_id,c.date_deadline
89             )""")
90
91 crm_helpdesk_report()
92
93 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: