[FIX] website_event: display unconfirmed events too
[odoo/odoo.git] / addons / project / report / project_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 openerp.osv import fields, osv
23 from openerp import tools
24
25
26 class report_project_task_user(osv.osv):
27     _name = "report.project.task.user"
28     _description = "Tasks by user and project"
29     _auto = False
30     _columns = {
31         'name': fields.char('Task Summary', size=128, readonly=True),
32         'user_id': fields.many2one('res.users', 'Assigned To', readonly=True),
33         'date_start': fields.date('Assignation Date', readonly=True),
34         'no_of_days': fields.integer('# of Days', size=128, readonly=True),
35         'date_end': fields.date('Ending Date', readonly=True),
36         'date_deadline': fields.date('Deadline', readonly=True),
37         'date_last_stage_update': fields.date('Last Stage Update', readonly=True),
38         'project_id': fields.many2one('project.project', 'Project', readonly=True),
39         'hours_planned': fields.float('Planned Hours', readonly=True),
40         'hours_effective': fields.float('Effective Hours', readonly=True),
41         'hours_delay': fields.float('Avg. Plan.-Eff.', readonly=True),
42         'remaining_hours': fields.float('Remaining Hours', readonly=True),
43         'progress': fields.float('Progress', readonly=True, group_operator='avg'),
44         'total_hours': fields.float('Total Hours', readonly=True),
45         'closing_days': fields.float('Days to Close', digits=(16,2), readonly=True, group_operator="avg",
46                                        help="Number of Days to close the task"),
47         'opening_days': fields.float('Days to Assign', digits=(16,2), readonly=True, group_operator="avg",
48                                        help="Number of Days to Open the task"),
49         'delay_endings_days': fields.float('Overpassed Deadline', digits=(16,2), readonly=True),
50         'nbr': fields.integer('# of tasks', readonly=True),
51         'priority': fields.selection([('0','Low'), ('1','Normal'), ('2','High')],
52             string='Priority', readonly=True),
53         'state': fields.selection([('draft', 'Draft'), ('open', 'In Progress'), ('pending', 'Pending'), ('cancelled', 'Cancelled'), ('done', 'Done')],'Status', readonly=True),
54         'company_id': fields.many2one('res.company', 'Company', readonly=True),
55         'partner_id': fields.many2one('res.partner', 'Contact', readonly=True),
56         'stage_id': fields.many2one('project.task.type', 'Stage'),
57     }
58     _order = 'name desc, project_id'
59
60     def init(self, cr):
61         tools.sql.drop_view_if_exists(cr, 'report_project_task_user')
62         cr.execute("""
63             CREATE view report_project_task_user as
64               SELECT
65                     (select 1 ) AS nbr,
66                     t.id as id,
67                     date_trunc('day',t.date_start) as date_start,
68                     date_trunc('day',t.date_end) as date_end,
69                     date_trunc('day',t.date_last_stage_update) as date_last_stage_update,
70                     to_date(to_char(t.date_deadline, 'dd-MM-YYYY'),'dd-MM-YYYY') as date_deadline,
71 --                    sum(cast(to_char(date_trunc('day',t.date_end) - date_trunc('day',t.date_start),'DD') as int)) as no_of_days,
72                     abs((extract('epoch' from (t.write_date-t.date_start)))/(3600*24))  as no_of_days,
73                     t.user_id,
74                     progress as progress,
75                     t.project_id,
76                     t.effective_hours as hours_effective,
77                     t.priority,
78                     t.name as name,
79                     t.company_id,
80                     t.partner_id,
81                     t.stage_id as stage_id,
82                     remaining_hours as remaining_hours,
83                     total_hours as total_hours,
84                     t.delay_hours as hours_delay,
85                     planned_hours as hours_planned,
86                     (extract('epoch' from (t.write_date-t.create_date)))/(3600*24)  as closing_days,
87                     (extract('epoch' from (t.date_start-t.create_date)))/(3600*24)  as opening_days,
88                     abs((extract('epoch' from (t.date_deadline-t.write_date)))/(3600*24))  as delay_endings_days
89               FROM project_task t
90                 WHERE t.active = 'true'
91                 GROUP BY
92                     t.id,
93                     remaining_hours,
94                     t.effective_hours,
95                     progress,
96                     total_hours,
97                     planned_hours,
98                     hours_delay,
99                     create_date,
100                     write_date,
101                     date_start,
102                     date_end,
103                     date_deadline,
104                     date_last_stage_update,
105                     t.user_id,
106                     t.project_id,
107                     t.priority,
108                     name,
109                     t.company_id,
110                     t.partner_id,
111                     stage_id
112         """)