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 mx import DateTime
26 from osv import fields, osv
27 from tools.translate import _
29 class hr_timesheet_group(osv.osv):
30 _name = "hr.timesheet.group"
31 _description = "Working Time"
33 'name' : fields.char("Group name", size=64, required=True),
34 'timesheet_id' : fields.one2many('hr.timesheet', 'tgroup_id', 'Working Time'),
35 'manager' : fields.many2one('res.users', 'Workgroup manager'),
38 # TODO: improve; very slow !
39 # bug if transition to another period
41 def interval_get(self, cr, uid, id, dt_from, hours, byday=True):
43 return [(dt_from,dt_from+DateTime.RelativeDateTime(hours=int(hours)*3))]
48 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))
49 for (hour_from,hour_to) in cr.fetchall():
53 hour_from = '%02d:%02d' % (math.floor(abs(hour_from)),round(abs(hour_from)%1+0.01,2) * 60)
54 hour_to = '%02d:%02d' % (math.floor(abs(hour_to)),round(abs(hour_to)%1+0.01,2) * 60)
56 h1,m1 = map(int,hour_from.split(':'))
57 h2,m2 = map(int,hour_to.split(':'))
58 d1 = DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,h1,m1)
59 d2 = DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,h2,m2)
61 date1 = max(dt_from,d1)
62 if date1+DateTime.RelativeDateTime(hours=todo)<=d2:
63 result.append((date1, date1+DateTime.RelativeDateTime(hours=todo)))
66 todo -= (d2-date1).hours
67 result.append((date1, d2))
68 dt_from = DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day)+DateTime.RelativeDateTime(days=1)
70 if cycle>7 and todo==hours:
71 return [(dt_from,dt_from+DateTime.RelativeDateTime(hours=hours*3))]
75 if (result[i][0]-result[i-1][1]).days<1:
76 result[i-1]=(result[i-1][0],result[i][1])
84 class hr_employee_category(osv.osv):
85 _name = "hr.employee.category"
86 _description = "Employee Category"
89 'name' : fields.char("Category", size=64, required=True),
90 'parent_id': fields.many2one('hr.employee.category', 'Parent Category', select=True),
91 'child_ids': fields.one2many('hr.employee.category', 'parent_id', 'Child Categories')
94 def _check_recursion(self, cr, uid, ids):
97 cr.execute('select distinct parent_id from hr_employee_category where id in ('+','.join(map(str,ids))+')')
98 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
105 (_check_recursion, 'Error ! You cannot create recursive Categories.', ['parent_id'])
108 hr_employee_category()
110 class hr_employee(osv.osv):
111 _name = "hr.employee"
112 _description = "Employee"
115 'name' : fields.char("Employee", size=128, required=True),
116 'active' : fields.boolean('Active'),
117 'company_id': fields.many2one('res.company', 'Company'),
118 'user_id' : fields.many2one('res.users', 'Related User'),
120 'country_id' : fields.many2one('res.country', 'Nationality'),
121 'birthday' : fields.date("Birthday"),
122 'ssnid': fields.char('SSN No', size=32),
123 'sinid': fields.char('SIN No', size=32),
124 'otherid': fields.char('Other ID', size=32),
125 'gender': fields.selection([('',''),('male','Male'),('female','Female')], 'Gender'),
126 'marital': fields.selection([('maried','Maried'),('unmaried','Unmaried'),('divorced','Divorced'),('other','Other')],'Marital Status', size=32),
128 'address_id': fields.many2one('res.partner.address', 'Working Address'),
129 'work_phone': fields.char('Work Phone', size=32),
130 'work_email': fields.char('Work Email', size=128),
131 'work_location': fields.char('Office Location', size=32),
133 'notes': fields.text('Notes'),
134 'parent_id': fields.many2one('hr.employee', 'Manager', select=True),
135 'category_id' : fields.many2one('hr.employee.category', 'Category'),
136 'child_ids': fields.one2many('hr.employee', 'parent_id','Subordinates'),
139 'active' : lambda *a: True,
142 def _check_recursion(self, cr, uid, ids):
145 cr.execute('select distinct parent_id from hr_employee where id in ('+','.join(map(str,ids))+')')
146 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
153 (_check_recursion, 'Error ! You cannot create recursive Hierarchy of Employees.', ['parent_id'])
158 class hr_timesheet(osv.osv):
159 _name = "hr.timesheet"
160 _description = "Timesheet Line"
162 'name' : fields.char("Name", size=64, required=True),
163 'dayofweek': fields.selection([('0','Monday'),('1','Tuesday'),('2','Wednesday'),('3','Thursday'),('4','Friday'),('5','Saturday'),('6','Sunday')], 'Day of week'),
164 'date_from' : fields.date('Starting date'),
165 'hour_from' : fields.float('Work from', size=8, required=True),
166 'hour_to' : fields.float("Work to", size=8, required=True),
167 'tgroup_id' : fields.many2one("hr.timesheet.group", "Employee's timesheet group", select=True),
169 _order = 'dayofweek, hour_from'