1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
22 from osv import fields,osv
25 class report_project_task_user(osv.osv):
26 _name = "report.project.task.user"
27 _description = "Tasks by user and project"
30 'name': fields.char('Task Summary', size=128, readonly=True),
31 'day': fields.char('Day', size=128, readonly=True),
32 'year': fields.char('Year',size=64,required=False, readonly=True),
33 'user_id':fields.many2one('res.users', 'Assigned To', readonly=True),
34 'date_start': fields.date('Starting Date',readonly=True),
35 'no_of_days': fields.integer('# of Days', size=128, readonly=True),
36 'description': fields.text('Description',readonly=True),
37 'date_end': fields.date('Ending Date',readonly=True),
38 'date_deadline': fields.date('Deadline',readonly=True),
39 'project_id':fields.many2one('project.project', 'Project', readonly=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 'remaining_hours': fields.float('Remaining Hours', readonly=True),
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 Open', digits=(16,2), readonly=True, group_operator="avg",
48 help="Number of Days to Open the task"),
49 'nbr': fields.integer('# of tasks', readonly=True),
50 'priority' : fields.selection([('4','Very Low'),
55 'Importance',readonly=True),
56 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
57 ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
58 'state': fields.selection([
60 ('open', 'In Progress'),
61 ('pending', 'Pending'),
62 ('cancelled', 'Cancelled'),
64 'State', readonly=True),
65 'company_id': fields.many2one('res.company', 'Company',readonly=True),
66 'partner_id': fields.many2one('res.partner', 'Partner',readonly=True),
67 'type': fields.many2one('project.task.type', 'Stage',readonly=True),
70 _order = 'name desc, project_id'
72 tools.sql.drop_view_if_exists(cr, 'report_project_task_user')
74 create or replace view report_project_task_user as (
77 to_char(date_start, 'YYYY') as year,
78 to_char(date_start, 'MM') as month,
79 to_char(date_start, 'YYYY-MM-DD') as day,
80 count(distinct t.id) as nbr,
81 date_trunc('day',t.date_start) as date_start,
82 date_trunc('day',t.date_end) as date_end,
83 to_date(to_char(t.date_deadline, 'dd-MM-YYYY'),'dd-MM-YYYY') as date_deadline,
84 sum(cast(to_char(date_trunc('day',t.date_end) - date_trunc('day',t.date_start),'DD') as int)) as no_of_days,
93 sum(remaining_hours) as remaining_hours,
94 sum(total_hours) as total_hours,
95 sum(planned_hours) as hours_planned,
96 avg(extract('epoch' from (t.date_end-t.create_date)))/(3600*24) as closing_days,
97 avg(extract('epoch' from (t.date_start-t.create_date)))/(3600*24) as opening_days,
98 sum(w.hours) as hours_effective,
99 ((sum(planned_hours)-sum(w.hours))/count(distinct t.id))::decimal(16,2) as hours_delay
101 left join project_task_work w on (t.id=w.task_id)
103 to_char(date_start, 'YYYY'),
104 to_char(date_start, 'MM'),
108 date_trunc('day',t.date_end),
109 to_date(to_char(t.date_deadline, 'dd-MM-YYYY'),'dd-MM-YYYY'),
118 report_project_task_user()
120 #This class is generated for project deshboard purpose
121 class project_vs_remaining_hours(osv.osv):
122 _name = "project.vs.remaining.hours"
123 _description = " Project vs Remaining hours"
126 'project': fields.char('Project', size=128, required=True),
127 'remaining_hours': fields.float('Remaining Hours', readonly=True),
128 'state': fields.selection([('draft','Draft'),('open','Open'), ('pending','Pending'),('cancelled', 'Cancelled'),('close','Close'),('template', 'Template')], 'State', required=True,readonly=True)
130 _order = 'project desc'
132 tools.sql.drop_view_if_exists(cr, 'project_vs_remaining_hours')
134 create or replace view project_vs_remaining_hours as (
140 sum(pt.remaining_hours) as remaining_hours
141 from project_project as pp,
142 account_analytic_account as aaa,
144 where aaa.id=pp.category_id and pt.project_id=pp.id and pp.category_id=aaa.id
145 group by aaa.user_id,aaa.state,aaa.name
152 sum(pt.remaining_hours) as remaining_hours
153 from project_project as pp,
154 project_user_rel as pur,
155 account_analytic_account as aaa,
157 where pur.project_id=pp.id and pt.project_id=pp.id and pp.category_id=aaa.id
158 group by pur.uid,aaa.state,aaa.name
161 project_vs_remaining_hours()
163 class task_by_days(osv.osv):
164 _name = "task.by.days"
165 _description = "Task By Days"
168 'day': fields.char('Day', size=128, required=True),
169 'state': fields.selection([('draft', 'Draft'),('open', 'In Progress'),('pending', 'Pending'), ('cancelled', 'Cancelled'), ('done', 'Done')], 'State', readonly=True, required=True),
170 'total_task': fields.float('Total tasks', readonly=True),
171 'project_id':fields.many2one('project.project','Project')
175 tools.sql.drop_view_if_exists(cr, 'task_by_days')
177 create or replace view task_by_days as (
180 to_char(pt.create_date, 'YYYY-MM-DD') as day,
181 count(*) as total_task,
187 to_char(pt.create_date, 'YYYY-MM-DD'),pt.state,pt.project_id
192 class task_by_days_vs_planned_hours(osv.osv):
193 _name = "task.by.days.vs.planned.hours"
194 _description = "Task By Days vs Planned Hours"
197 'day': fields.char('Day', size=128, required=True),
198 'planned_hour': fields.float('Planned Hours', readonly=True),
199 'project_id':fields.many2one('project.project','Project')
203 tools.sql.drop_view_if_exists(cr, 'task_by_days_vs_planned_hours')
205 create or replace view task_by_days_vs_planned_hours as (
208 to_char(pt.create_date, 'YYYY-MM-DD') as day,
209 sum(planned_hours) as planned_hour,
214 to_char(pt.create_date, 'YYYY-MM-DD'),pt.project_id
217 task_by_days_vs_planned_hours()
218 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: