[FORWARD] Forward port of addons until revision 8711
[odoo/odoo.git] / addons / project_issue / report / project_issue_report.py
1
2 # -*- coding: utf-8 -*-
3 ##############################################################################
4 #
5 #    OpenERP, Open Source Management Solution
6 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU Affero General Public License as
10 #    published by the Free Software Foundation, either version 3 of the
11 #    License, or (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU Affero General Public License for more details.
17 #
18 #    You should have received a copy of the GNU Affero General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 from openerp.osv import fields,osv
24 from openerp import tools
25 from openerp.addons.crm import crm
26
27 AVAILABLE_STATES = [
28     ('draft','Draft'),
29     ('open','Open'),
30     ('cancel', 'Cancelled'),
31     ('done', 'Closed'),
32     ('pending','Pending')
33 ]
34 class project_issue_report(osv.osv):
35     _name = "project.issue.report"
36     _auto = False
37
38     _columns = {
39         'name': fields.char('Year', size=64, required=False, readonly=True),
40         'section_id':fields.many2one('crm.case.section', 'Sale Team', readonly=True),
41         'state': fields.selection(AVAILABLE_STATES, 'Status', size=16, readonly=True),
42         'month':fields.selection([('01', 'January'), ('02', 'February'), \
43                                   ('03', 'March'), ('04', 'April'),\
44                                   ('05', 'May'), ('06', 'June'), \
45                                   ('07', 'July'), ('08', 'August'),\
46                                   ('09', 'September'), ('10', 'October'),\
47                                   ('11', 'November'), ('12', 'December')], 'Month', readonly=True),
48         'company_id': fields.many2one('res.company', 'Company', readonly=True),
49         'day': fields.char('Day', size=128, readonly=True),
50         'opening_date': fields.date('Date of Opening', readonly=True),
51         'creation_date': fields.date('Creation Date', readonly=True),
52         'date_closed': fields.date('Date of Closing', readonly=True),
53         'stage_id': fields.many2one('project.task.type', 'Stage'),
54         'nbr': fields.integer('# of Issues', readonly=True),
55         'working_hours_open': fields.float('Avg. Working Hours to Open', readonly=True, group_operator="avg"),
56         'working_hours_close': fields.float('Avg. Working Hours to Close', readonly=True, group_operator="avg"),
57         'delay_open': fields.float('Avg. Delay to Open', digits=(16,2), readonly=True, group_operator="avg",
58                                        help="Number of Days to open the project issue."),
59         'delay_close': fields.float('Avg. Delay to Close', digits=(16,2), readonly=True, group_operator="avg",
60                                        help="Number of Days to close the project issue"),
61         'company_id' : fields.many2one('res.company', 'Company'),
62         'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
63         'project_id':fields.many2one('project.project', 'Project',readonly=True),
64         'version_id': fields.many2one('project.issue.version', 'Version'),
65         'user_id' : fields.many2one('res.users', 'Assigned to',readonly=True),
66         'partner_id': fields.many2one('res.partner','Contact'),
67         'channel_id': fields.many2one('crm.case.channel', 'Channel',readonly=True),
68         'task_id': fields.many2one('project.task', 'Task'),
69         'email': fields.integer('# Emails', size=128, readonly=True),
70     }
71
72     def init(self, cr):
73         tools.drop_view_if_exists(cr, 'project_issue_report')
74         cr.execute("""
75             CREATE OR REPLACE VIEW project_issue_report AS (
76                 SELECT
77                     c.id as id,
78                     to_char(c.create_date, 'YYYY') as name,
79                     to_char(c.create_date, 'MM') as month,
80                     to_char(c.create_date, 'YYYY-MM-DD') as day,
81                     to_char(c.date_open, 'YYYY-MM-DD') as opening_date,
82                     to_char(c.create_date, 'YYYY-MM-DD') as creation_date,
83                     c.state,
84                     c.user_id,
85                     c.working_hours_open,
86                     c.working_hours_close,
87                     c.section_id,
88                     c.stage_id,
89                     to_char(c.date_closed, 'YYYY-mm-dd') as date_closed,
90                     c.company_id as company_id,
91                     c.priority as priority,
92                     c.project_id as project_id,
93                     c.version_id as version_id,
94                     1 as nbr,
95                     c.partner_id,
96                     c.channel_id,
97                     c.task_id,
98                     date_trunc('day',c.create_date) as create_date,
99                     c.day_open as delay_open,
100                     c.day_close as delay_close,
101                     (SELECT count(id) FROM mail_message WHERE model='project.issue' AND res_id=c.id) AS email
102
103                 FROM
104                     project_issue c
105                 WHERE c.active= 'true'
106             )""")
107
108
109 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: