[IMP] update version in po(t) files
[odoo/odoo.git] / addons / report_project / report_project.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (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 General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 from osv import fields,osv
24
25 class report_project_task_user(osv.osv):
26     _name = "report.project.task.user"
27     _description = "Tasks by user and project"
28     _auto = False
29     _columns = {
30         'name': fields.date('Month', readonly=True),
31         'user_id':fields.many2one('res.users', 'User', readonly=True),
32         'project_id':fields.many2one('project.project', 'Project', readonly=True),
33         'hours_planned': fields.float('Planned Hours', readonly=True),
34         'hours_effective': fields.float('Effective Hours', readonly=True),
35         'hours_delay': fields.float('Avg. Plan.-Eff.', readonly=True),
36         'closing_days': fields.char('Avg Closing Delay', size=64, readonly=True),
37         'task_closed': fields.integer('Task Closed', readonly=True),
38     }
39     _order = 'name desc, project_id'
40     def init(self, cr):
41         cr.execute("""
42             create or replace view report_project_task_user as (
43                 select
44                     min(t.id) as id,
45                     to_char(date_close, 'YYYY-MM-01') as name,
46                     count(distinct t.id) as task_closed,
47                     t.user_id,
48                     t.project_id,
49                     sum(planned_hours) as hours_planned,
50                     to_char(avg(date_close::abstime-t.create_date::timestamp), 'DD"d" HH12:MI:SS') as closing_days,
51                     sum(w.hours) as hours_effective,
52                     ((sum(planned_hours)-sum(w.hours))/count(distinct t.id))::decimal(16,2) as hours_delay
53                 from project_task t
54                     left join project_task_work w on (t.id=w.task_id)
55                 where
56                     t.state='done'
57                 group by
58                     to_char(date_close, 'YYYY-MM-01'),t.user_id,project_id
59             )
60         """)
61 report_project_task_user()
62
63
64 class report_project_task(osv.osv):
65     _name = "report.project.task"
66     _description = "Tasks by project"
67     _auto = False
68     _columns = {
69         'name': fields.date('Month', readonly=True),
70         'project_id':fields.many2one('project.project', 'Project', readonly=True),
71         'hours_planned': fields.float('Planned Hours', readonly=True),
72         'hours_effective': fields.float('Effective Hours', readonly=True),
73         'hours_delay': fields.float('Avg. Plan.-Eff.', readonly=True),
74         'closing_days': fields.char('Avg Closing Delay', size=64, readonly=True),
75         'task_closed': fields.integer('Task Closed', readonly=True),
76     }
77     _order = 'name desc, project_id'
78     def init(self, cr):
79         cr.execute("""
80             create or replace view report_project_task as (
81                 select
82                     min(t.id) as id,
83                     to_char(date_close, 'YYYY-MM-01') as name,
84                     count(distinct t.id) as task_closed,
85                     t.project_id,
86                     sum(planned_hours) as hours_planned,
87                     to_char(avg(date_close::abstime-t.create_date::timestamp), 'DD"d" HH12:MI:SS') as closing_days,
88                     sum(w.hours) as hours_effective,
89                     ((sum(planned_hours)-sum(w.hours))/count(distinct t.id))::decimal(16,2) as hours_delay
90                 from project_task t
91                     left join project_task_work w on (t.id=w.task_id)
92                 where
93                     t.state='done'
94                 group by
95                     to_char(date_close, 'YYYY-MM-01'),project_id
96             )
97         """)
98 report_project_task()
99
100
101
102
103
104 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
105