CLIENT, ALL: use the action name for the tabs name in the client
[odoo/odoo.git] / addons / report_project / report_project.py
1 ##############################################################################
2 #
3 # Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
4 #
5 # $Id: project.py 1005 2005-07-25 08:41:42Z nicoe $
6 #
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
12 # Service Company
13 #
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27 #
28 ##############################################################################
29
30 from osv import fields,osv
31
32 class report_project_task_user(osv.osv):
33     _name = "report.project.task.user"
34     _description = "Tasks by user and project"
35     _auto = False
36     _columns = {
37         'name': fields.date('Month', readonly=True),
38         'user_id':fields.many2one('res.users', 'User', readonly=True, relate=True),
39         'project_id':fields.many2one('project.project', 'Project', readonly=True, relate=True),
40         'hours_planned': fields.float('Planned Hours', readonly=True),
41         'hours_effective': fields.float('Effective Hours', readonly=True),
42         'hours_delay': fields.float('Avg. Plan.-Eff.', readonly=True),
43         'closing_days': fields.char('Avg Closing Delay', size=64, readonly=True),
44         'task_closed': fields.integer('Task Closed', readonly=True),
45     }
46     _order = 'name desc, project_id'
47     def init(self, cr):
48         cr.execute("""
49             create or replace view report_project_task_user as (
50                 select
51                     min(t.id) as id,
52                     substring(date_close for 7)||'-01' as name,
53                     count(distinct t.id) as task_closed,
54                     t.user_id,
55                     t.project_id,
56                     sum(planned_hours) as hours_planned,
57                     to_char(avg(date_close::abstime-t.create_date::timestamp), 'DD"d" HH12:MI:SS') as closing_days,
58                     sum(w.hours) as hours_effective,
59                     ((sum(planned_hours)-sum(w.hours))/count(distinct t.id))::decimal(16,2) as hours_delay
60                 from project_task t
61                     left join project_task_work w on (t.id=w.task_id)
62                 where
63                     t.state='done'
64                 group by
65                     substring(date_close for 7),t.user_id,project_id
66             )
67         """)
68 report_project_task_user()
69
70
71 class report_project_task(osv.osv):
72     _name = "report.project.task"
73     _description = "Tasks by project"
74     _auto = False
75     _columns = {
76         'name': fields.date('Month', readonly=True),
77         'project_id':fields.many2one('project.project', 'Project', readonly=True, relate=True),
78         'hours_planned': fields.float('Planned Hours', readonly=True),
79         'hours_effective': fields.float('Effective Hours', readonly=True),
80         'hours_delay': fields.float('Avg. Plan.-Eff.', readonly=True),
81         'closing_days': fields.char('Avg Closing Delay', size=64, readonly=True),
82         'task_closed': fields.integer('Task Closed', readonly=True),
83     }
84     _order = 'name desc, project_id'
85     def init(self, cr):
86         cr.execute("""
87             create or replace view report_project_task as (
88                 select
89                     min(t.id) as id,
90                     substring(date_close for 7)||'-01' as name,
91                     count(distinct t.id) as task_closed,
92                     t.project_id,
93                     sum(planned_hours) as hours_planned,
94                     to_char(avg(date_close::abstime-t.create_date::timestamp), 'DD"d" HH12:MI:SS') as closing_days,
95                     sum(w.hours) as hours_effective,
96                     ((sum(planned_hours)-sum(w.hours))/count(distinct t.id))::decimal(16,2) as hours_delay
97                 from project_task t
98                     left join project_task_work w on (t.id=w.task_id)
99                 where
100                     t.state='done'
101                 group by
102                     substring(date_close for 7),project_id
103             )
104         """)
105 report_project_task()
106
107
108
109