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('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'),
48 'State', readonly=True),
51 _order = 'name desc, project_id'
53 tools.sql.drop_view_if_exists(cr, 'report_project_task_user')
55 create or replace view report_project_task_user as (
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,
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
72 left join project_task_work w on (t.id=w.task_id)
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,
81 report_project_task_user()
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"
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)
93 _order = 'project desc'
95 tools.sql.drop_view_if_exists(cr, 'project_vs_remaining_hours')
97 create or replace view project_vs_remaining_hours as (
101 sum(pt.remaining_hours) as remaining_hours,
105 project_project as p,
106 account_analytic_account as a
108 pt.project_id=p.id and
114 project_vs_remaining_hours()
116 class task_by_days(osv.osv):
117 _name = "task.by.days"
118 _description = "Task By Days"
121 'day': fields.char('Day', size=128, required=True),
122 'total_task': fields.float('Total tasks', readonly=True)
126 tools.sql.drop_view_if_exists(cr, 'task_by_days')
128 create or replace view task_by_days as (
131 to_char(pt.create_date, 'YYYY-MM-DD') as day,
132 count(*) as total_task
136 to_char(pt.create_date, 'YYYY-MM-DD')
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"
146 'day': fields.char('Day', size=128, required=True),
147 'planned_hour': fields.float('Planned Hours', readonly=True)
151 tools.sql.drop_view_if_exists(cr, 'task_by_days_vs_planned_hours')
153 create or replace view task_by_days_vs_planned_hours as (
156 to_char(pt.create_date, 'YYYY-MM-DD') as day,
157 sum(planned_hours) as planned_hour
161 to_char(pt.create_date, 'YYYY-MM-DD')
164 task_by_days_vs_planned_hours()
165 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: