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',readonly=True),
33 'description': fields.text('Description',readonly=True),
34 'date_end': fields.datetime('Ending Date',readonly=True),
35 'date_deadline': fields.date('Deadline',readonly=True),
36 'project_id':fields.many2one('project.project', 'Project', readonly=True),
37 'hours_planned': fields.float('Planned Hours', readonly=True),
38 'hours_effective': fields.float('Effective Hours', readonly=True),
39 'hours_delay': fields.float('Avg. Plan.-Eff.', readonly=True),
40 'closing_days': fields.char('Avg Closing Delay', size=64, readonly=True),
41 'nbr': fields.integer('#Number of tasks', readonly=True),
42 'priority' : fields.selection([('4','Very Low'),
47 'Importance',readonly=True),
48 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
49 ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
50 'state': fields.selection([
52 ('open', 'In Progress'),
53 ('pending', 'Pending'),
54 ('cancelled', 'Cancelled'),
56 'State', readonly=True),
57 'company_id': fields.many2one('res.company', 'Company',readonly=True),
58 'partner_id': fields.many2one('res.partner', 'Partner',readonly=True),
59 'type': fields.many2one('project.task.type', 'Stage',readonly=True),
64 _order = 'name desc, project_id'
66 tools.sql.drop_view_if_exists(cr, 'report_project_task_user')
68 create or replace view report_project_task_user as (
71 to_char(date_start, 'YYYY') as name,
72 to_char(date_start, 'MM') as month,
73 count(distinct t.id) as nbr,
74 date_trunc('day',t.date_start) as date_start,
75 date_trunc('day',t.date_end) as date_end,
76 to_date(to_char(t.date_deadline, 'dd-MM-YYYY'),'dd-MM-YYYY') as date_deadline,
84 sum(planned_hours) as hours_planned,
85 to_char(avg(date_end::abstime-t.create_date::timestamp), 'DD"d" HH24:MI:SS') as closing_days,
86 sum(w.hours) as hours_effective,
87 ((sum(planned_hours)-sum(w.hours))/count(distinct t.id))::decimal(16,2) as hours_delay
89 left join project_task_work w on (t.id=w.task_id)
91 to_char(date_start, 'YYYY'),
92 to_char(date_start, 'MM'),
97 to_date(to_char(t.date_deadline, 'dd-MM-YYYY'),'dd-MM-YYYY'),
105 report_project_task_user()
107 #This class is generated for project deshboard purpose
108 class project_vs_remaining_hours(osv.osv):
109 _name = "project.vs.remaining.hours"
110 _description = " Project vs Remaining hours"
113 'project': fields.char('Project', size=128, required=True),
114 'remaining_hours': fields.float('Remaining Hours', readonly=True),
115 'state': fields.selection([('draft','Draft'),('open','Open'), ('pending','Pending'),('cancelled', 'Cancelled'),('close','Close'),('template', 'Template')], 'State', required=True,readonly=True)
117 _order = 'project desc'
119 tools.sql.drop_view_if_exists(cr, 'project_vs_remaining_hours')
121 create or replace view project_vs_remaining_hours as (
125 sum(pt.remaining_hours) as remaining_hours,
129 project_project as p,
130 account_analytic_account as a
132 pt.project_id=p.id and
138 project_vs_remaining_hours()
140 class task_by_days(osv.osv):
141 _name = "task.by.days"
142 _description = "Task By Days"
145 'day': fields.char('Day', size=128, required=True),
146 'state': fields.selection([('draft', 'Draft'),('open', 'In Progress'),('pending', 'Pending'), ('cancelled', 'Cancelled'), ('done', 'Done')], 'State', readonly=True, required=True),
147 'total_task': fields.float('Total tasks', readonly=True),
148 'project_id':fields.many2one('project.project','Project')
152 tools.sql.drop_view_if_exists(cr, 'task_by_days')
154 create or replace view task_by_days as (
157 to_char(pt.create_date, 'YYYY-MM-DD') as day,
158 count(*) as total_task,
164 to_char(pt.create_date, 'YYYY-MM-DD'),pt.state,pt.project_id
169 class task_by_days_vs_planned_hours(osv.osv):
170 _name = "task.by.days.vs.planned.hours"
171 _description = "Task By Days vs Planned Hours"
174 'day': fields.char('Day', size=128, required=True),
175 'planned_hour': fields.float('Planned Hours', readonly=True),
176 'project_id':fields.many2one('project.project','Project')
180 tools.sql.drop_view_if_exists(cr, 'task_by_days_vs_planned_hours')
182 create or replace view task_by_days_vs_planned_hours as (
185 to_char(pt.create_date, 'YYYY-MM-DD') as day,
186 sum(planned_hours) as planned_hour,
191 to_char(pt.create_date, 'YYYY-MM-DD'),pt.project_id
194 task_by_days_vs_planned_hours()
195 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: