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 openerp.osv import fields,osv
25 from openerp import tools
27 class report_timesheet_task_user(osv.osv):
28 _name = "report.timesheet.task.user"
32 def get_hrs_timesheet(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 obj = self.pool.get('hr_timesheet_sheet.sheet.day')
37 sheet_ids = obj.search(cr, uid, [('sheet_id.user_id','=',record.user_id.id),('name','>=',record.name),('name','<=',last_date.strftime('%Y-%m-%d'))])
38 data_days = obj.read(cr, uid, sheet_ids, ['name','sheet_id.user_id','total_attendance'])
40 for day_attendance in data_days:
41 total += day_attendance['total_attendance']
42 result[record.id] = total
46 'name': fields.char('Date',size=64),
47 'year': fields.char('Year',size=64,required=False, 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 'user_id': fields.many2one('res.users', 'User',readonly=True),
51 'timesheet_hrs': fields.function(get_hrs_timesheet, string="Timesheet Hours"),
52 'task_hrs' : fields.float('Task Hours'),
56 tools.drop_view_if_exists(cr, 'report_timesheet_task_user')
57 cr.execute(""" create or replace view report_timesheet_task_user as (
59 ((r.id*12)+to_number(months.m_id,'999999'))::integer as id,
62 to_char(to_date(months.name, 'YYYY/MM/DD'),'YYYY') as year,
63 to_char(to_date(months.name, 'YYYY/MM/DD'),'MM') as month,
64 (select sum(hours) from project_task_work where user_id = r.id and date between to_date(months.name, 'YYYY/MM/DD') and (to_date(months.name, 'YYYY/MM/DD') + interval '1 month' -
65 interval '1 day') ) as task_hrs
67 (select to_char(p.date,'YYYY-MM-01') as name,
68 to_char(p.date,'YYYYMM') as m_id
69 from project_task_work p
72 select to_char(h.name,'YYYY-MM-01') as name,
73 to_char(h.name,'YYYYMM') as m_id
74 from hr_timesheet_sheet_sheet_day h) as months
77 r.id,months.m_id,months.name,
78 to_char(to_date(months.name, 'YYYY/MM/DD'),'YYYY') ,
79 to_char(to_date(months.name, 'YYYY/MM/DD'),'MM')
82 report_timesheet_task_user()
84 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: