[IMP]:Improved project,scrum,project_issue
[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 osv import fields,osv
23 import tools
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.char('Year',size=64,required=False, readonly=True),
31         'user_id':fields.many2one('res.users', 'User', readonly=True),
32         'date_start': fields.datetime('Starting Date'),
33         'date_end': fields.datetime('Ending Date'),
34         'date_deadline': fields.date('Deadline'),
35         'project_id':fields.many2one('project.project', 'Project', readonly=True),
36         'hours_planned': fields.float('Planned Hours', readonly=True),
37         'hours_effective': fields.float('Effective Hours', readonly=True),
38         'hours_delay': fields.float('Avg. Plan.-Eff.', readonly=True),
39         'closing_days': fields.char('Avg Closing Delay', size=64, readonly=True),
40         'nbr': fields.integer('#Number of tasks', readonly=True),
41         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
42                           ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
43         'state': fields.selection([('draft', 'Draft'),
44                                    ('open', 'In Progress'),
45                                    ('pending', 'Pending'),
46                                    ('cancelled', 'Cancelled'),
47                                    ('done', 'Done')],
48                                 'State', readonly=True),
49
50     }
51     _order = 'name desc, project_id'
52     def init(self, cr):
53         tools.sql.drop_view_if_exists(cr, 'report_project_task_user')
54         cr.execute("""
55             create or replace view report_project_task_user as (
56                 select
57                     min(t.id) as id,
58                     to_char(date_start, 'YYYY') as name,
59                     to_char(date_start, 'MM') as month,
60                     count(distinct t.id) as nbr,
61                     date_trunc('day',t.date_start) as date_start,
62                     date_trunc('day',t.date_end) as date_end,
63                     date_trunc('day',t.date_deadline) as date_deadline,
64                     t.user_id,
65                     t.project_id,
66                     t.state,
67                     sum(planned_hours) as hours_planned,
68                     to_char(avg(date_end::abstime-t.create_date::timestamp), 'DD"d" HH24:MI:SS') as closing_days,
69                     sum(w.hours) as hours_effective,
70                     ((sum(planned_hours)-sum(w.hours))/count(distinct t.id))::decimal(16,2) as hours_delay
71                 from project_task t
72                     left join project_task_work w on (t.id=w.task_id)
73                 group by
74                     to_char(date_start, 'YYYY'),
75                     to_char(date_start, 'MM'),
76                     t.user_id,t.state,t.date_end,
77                     t.date_deadline,t.date_start,
78                     t.project_id
79             )
80         """)
81 report_project_task_user()
82
83 #This class is generated for project deshboard purpose
84 class project_vs_remaining_hours(osv.osv):
85     _name = "project.vs.remaining.hours"
86     _description = " Project vs Remaining hours"
87     _auto = False
88     _columns = {
89         'project': fields.char('Project', size=128, required=True),
90         'remaining_hours': fields.float('Remaining Hours', readonly=True),
91         'state': fields.selection([('draft','Draft'),('open','Open'), ('pending','Pending'),('cancelled', 'Cancelled'),('close','Close'),('template', 'Template')], 'State', required=True,readonly=True)
92     }
93     _order = 'project desc'
94     def init(self, cr):
95         tools.sql.drop_view_if_exists(cr, 'project_vs_remaining_hours')
96         cr.execute("""
97             create or replace view project_vs_remaining_hours as (
98                    select
99                        min(pt.id) as id,
100                        a.name as project,
101                        sum(pt.remaining_hours) as remaining_hours,
102                        a.state
103                     from
104                          project_task as pt,
105                          project_project as p,
106                          account_analytic_account as a
107                     where
108                         pt.project_id=p.id and
109                         p.category_id = a.id
110                     group by
111                         a.name,a.state
112             )
113         """)
114 project_vs_remaining_hours()
115
116 class task_by_days(osv.osv):
117     _name = "task.by.days"
118     _description = "Task By Days"
119     _auto = False
120     _columns = {
121         'day': fields.char('Day', size=128, required=True),
122         'total_task': fields.float('Total tasks', readonly=True)
123      }
124     _order = 'day desc'
125     def init(self, cr):
126         tools.sql.drop_view_if_exists(cr, 'task_by_days')
127         cr.execute("""
128             create or replace view task_by_days as (
129                 select
130                     min(pt.id) as id,
131                     to_char(pt.create_date, 'YYYY-MM-DD') as day,
132                     count(*) as total_task
133                 from
134                     project_task as pt
135                 group by
136                     to_char(pt.create_date, 'YYYY-MM-DD')
137             )
138         """)
139 task_by_days()
140
141 class task_by_days_vs_planned_hours(osv.osv):
142     _name = "task.by.days.vs.planned.hours"
143     _description = "Task By Days vs Planned Hours"
144     _auto = False
145     _columns = {
146         'day': fields.char('Day', size=128, required=True),
147         'planned_hour': fields.float('Planned Hours', readonly=True)
148      }
149     _order = 'day desc'
150     def init(self, cr):
151         tools.sql.drop_view_if_exists(cr, 'task_by_days_vs_planned_hours')
152         cr.execute("""
153             create or replace view task_by_days_vs_planned_hours as (
154                 select
155                     min(pt.id) as id,
156                     to_char(pt.create_date, 'YYYY-MM-DD') as day,
157                     sum(planned_hours) as planned_hour
158                 from
159                     project_task as pt
160                 group by
161                     to_char(pt.create_date, 'YYYY-MM-DD')
162             )
163         """)
164 task_by_days_vs_planned_hours()
165 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
166