1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
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.
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.
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/>.
21 ##############################################################################
23 from osv import fields,osv
26 class report_task_user_pipeline_open (osv.osv):
27 _name = "report.task.user.pipeline.open"
28 _description = "Tasks by user and project"
31 'user_id':fields.many2one('res.users', 'User', readonly=True),
32 'task_nbr': fields.float('Task Number', readonly=True),
33 'task_hrs': fields.float('Task Hours', readonly=True),
34 'task_progress': fields.float('Task Progress', readonly=True),
35 'company_id' : fields.many2one('res.company', 'Company'),
36 'task_state': fields.selection([('draft', 'Draft'),('open', 'Open'),('pending', 'Pending'), ('cancelled', 'Cancelled'), ('done', 'Done'),('no','No Task')], 'Status', readonly=True),
41 create or replace view report_task_user_pipeline_open as (
45 u.company_id as company_id,
46 count(t.*) as task_nbr,
47 sum(t.planned_hours) as task_hrs,
48 sum(t.planned_hours * (100 - t.progress) / 100) as task_progress,
49 case when t.state is null then 'no' else t.state end as task_state
53 project_task t on (u.id = t.user_id)
57 u.id, u.company_id, t.state
60 report_task_user_pipeline_open()
62 class report_closed_task(osv.osv):
63 _name = "report.closed.task"
64 _description = "Closed Task Report"
67 'sequence': fields.integer('Sequence', readonly=True),
68 'name': fields.char('Task summary', size=128, readonly=True),
69 'project_id': fields.many2one('project.project', 'Project', readonly=True),
70 'user_id': fields.many2one('res.users', 'Assigned to', readonly=True),
71 'date_deadline': fields.datetime('Deadline', readonly=True),
72 'planned_hours': fields.float('Planned Hours', readonly=True),
73 'delay_hours': fields.float('Delay Hours', readonly=True),
74 'progress': fields.float('Progress (%)', readonly=True),
75 'priority' : fields.selection([('4','Very Low'), ('3','Low'), ('2','Medium'), ('1','Urgent'), ('0','Very urgent')], 'Importance', readonly=True),
76 'state': fields.selection([('draft', 'Draft'),('open', 'In Progress'),('pending', 'Pending'), ('cancelled', 'Cancelled'), ('done', 'Done')], 'Status', readonly=True),
77 'remaining_hours': fields.float('Remaining Hours', readonly=True),
78 'date_close' : fields.datetime('Date Closed', readonly=True)
83 create or replace view report_closed_task as (
85 tsk.id as id, tsk.sequence as sequence, tsk.name as name,
86 tsk.project_id as project_id, tsk.user_id as user_id,
87 tsk.date_deadline as date_deadline, tsk.planned_hours as planned_hours,
88 tsk.delay_hours as delay_hours, tsk.progress as progress,
89 tsk.priority as priority, tsk.state as state,
90 tsk.remaining_hours as remaining_hours, tsk.date_close as date_close
94 (tsk.date_close <= CURRENT_DATE AND tsk.date_close > (CURRENT_DATE-15))
99 class report_timesheet_task_user(osv.osv):
100 _name = "report.timesheet.task.user"
104 def _get_task_hours(self, cr, uid, ids, name,args,context):
106 for record in self.browse(cr, uid, ids,context):
107 last_date = mx.DateTime.strptime(record.name, '%Y-%m-%d') + mx.DateTime.RelativeDateTime(months=1) - 1
108 task_obj=self.pool.get('project.task.work')
109 task_ids = task_obj.search(cr,uid,[('user_id','=',record.user_id.id),('date','>=',record.name),('date','<=',last_date.strftime('%Y-%m-%d'))])
110 tsk_hrs = task_obj.read(cr,uid,task_ids,['hours','date','user_id'])
113 total += hrs['hours']
114 result[record.id] = total
117 def get_hrs_timesheet(self, cr, uid, ids, name,args,context):
120 for record in self.browse(cr, uid, ids, context):
121 last_date = mx.DateTime.strptime(record.name, '%Y-%m-%d') + mx.DateTime.RelativeDateTime(months=1) - 1
122 obj=self.pool.get('hr_timesheet_sheet.sheet.day')
123 sheet_ids = obj.search(cr,uid,[('sheet_id.user_id','=',record.user_id.id),('name','>=',record.name),('name','<=',last_date.strftime('%Y-%m-%d'))])
124 data_days = obj.read(cr,uid,sheet_ids,['name','sheet_id.user_id','total_attendance'])
126 for day_attendance in data_days:
127 total += day_attendance['total_attendance']
128 result[record.id] = total
132 'name': fields.date('Month',readonly=True),
133 'user_id': fields.many2one('res.users', 'User',readonly=True),
134 'timesheet_hrs': fields.function(get_hrs_timesheet, method=True, string="Timesheet Hours"),
135 'task_hrs': fields.function(_get_task_hours, method=True, string="Task Hours"),
140 cr.execute(""" create or replace view report_timesheet_task_user as (
142 ((r.id*12)+to_number(months.m_id,'99'))::integer as id,
146 (select to_char(p.date,'YYYY-MM-01') as name,
147 to_char(p.date,'MM') as m_id
148 from project_task_work p
151 select to_char(h.name,'YYYY-MM-01') as name,
152 to_char(h.name,'MM') as m_id
153 from hr_timesheet_sheet_sheet_day h) as months) """)
155 report_timesheet_task_user()
157 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: