# -*- encoding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # ############################################################################## from mx import DateTime import time from osv import fields, osv from tools.translate import _ class hr_timesheet_group(osv.osv): _name = "hr.timesheet.group" _description = "Working Time" _columns = { 'name' : fields.char("Group name", size=64, required=True), 'timesheet_id' : fields.one2many('hr.timesheet', 'tgroup_id', 'Working Time'), 'manager' : fields.many2one('res.users', 'Workgroup manager'), } # # TODO: improve; very slow ! # bug if transition to another period # def interval_get(self, cr, uid, id, dt_from, hours, byday=True): if not id: return [(dt_from,dt_from+DateTime.RelativeDateTime(hours=int(hours)*3))] todo = hours cycle = 0 result = [] while todo>0: cr.execute("select hour_from,hour_to from hr_timesheet where dayofweek='%s' and tgroup_id=%s order by hour_from", (dt_from.day_of_week,id)) for (hour_from,hour_to) in cr.fetchall(): import math hour_from = '%02d:%02d' % (math.floor(abs(hour_from)),round(abs(hour_from)%1+0.01,2) * 60) hour_to = '%02d:%02d' % (math.floor(abs(hour_to)),round(abs(hour_to)%1+0.01,2) * 60) h1,m1 = map(int,hour_from.split(':')) h2,m2 = map(int,hour_to.split(':')) d1 = DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,h1,m1) d2 = DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,h2,m2) if dt_from7 and todo==hours: return [(dt_from,dt_from+DateTime.RelativeDateTime(hours=hours*3))] if byday: i = 1 while i