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 ##############################################################################
21 from datetime import datetime
22 from dateutil.relativedelta import relativedelta
24 from osv import fields,osv
27 class report_timesheet_task_user(osv.osv):
28 _name = "report.timesheet.task.user"
32 def _get_task_hours(self, cr, uid, ids, name,args,context):
34 for record in self.browse(cr, uid, ids,context):
35 last_date = datetime.strptime(record.name, '%Y-%m-%d') + relativedelta(months=1) - relativedelta(days=1)
36 task_obj = self.pool.get('project.task.work')
37 task_ids = task_obj.search(cr, uid, [('user_id','=',record.user_id.id),('date','>=',record.name),('date','<=',last_date.strftime('%Y-%m-%d'))])
38 tsk_hrs = task_obj.read(cr, uid, task_ids, ['hours','date','user_id'])
42 result[record.id] = total
45 def get_hrs_timesheet(self, cr, uid, ids, name,args,context):
48 for record in self.browse(cr, uid, ids, context):
49 last_date = datetime.strptime(record.name, '%Y-%m-%d') + relativedelta(months=1) - relativedelta(days=1)
50 obj = self.pool.get('hr_timesheet_sheet.sheet.day')
51 sheet_ids = obj.search(cr, uid, [('sheet_id.user_id','=',record.user_id.id),('name','>=',record.name),('name','<=',last_date.strftime('%Y-%m-%d'))])
52 data_days = obj.read(cr, uid, sheet_ids, ['name','sheet_id.user_id','total_attendance'])
54 for day_attendance in data_days:
55 total += day_attendance['total_attendance']
56 result[record.id] = total
60 'name': fields.char('Date',size=64),
61 'year': fields.char('Year',size=64,required=False, readonly=True),
62 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
63 ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
64 'user_id': fields.many2one('res.users', 'User',readonly=True),
65 'timesheet_hrs': fields.function(get_hrs_timesheet, string="Timesheet Hours"),
66 'task_hrs': fields.function(_get_task_hours, string="Task Hours"),
70 tools.drop_view_if_exists(cr, 'report_timesheet_task_user')
71 cr.execute(""" create or replace view report_timesheet_task_user as (
73 ((r.id*12)+to_number(months.m_id,'99'))::integer as id,
76 to_char(to_date(months.name, 'YYYY/MM/DD'),'YYYY') as year,
77 to_char(to_date(months.name, 'YYYY/MM/DD'),'MM') as month
79 (select to_char(p.date,'YYYY-MM-01') as name,
80 to_char(p.date,'MM') as m_id
81 from project_task_work p
84 select to_char(h.name,'YYYY-MM-01') as name,
85 to_char(h.name,'MM') as m_id
86 from hr_timesheet_sheet_sheet_day h) as months
89 r.id,months.m_id,months.name,
90 to_char(to_date(months.name, 'YYYY/MM/DD'),'YYYY') ,
91 to_char(to_date(months.name, 'YYYY/MM/DD'),'MM')
94 report_timesheet_task_user()
96 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: