1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 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 ##############################################################################
22 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'),
37 def interval_min_get(self, cr, uid, id, dt_from, hours):
39 return [(dt_from-DateTime.RelativeDateTime(hours=int(hours)*3), dt_from)]
44 current_hour = dt_from.hour
45 while (todo>0) and maxrecur:
46 cr.execute("select hour_from,hour_to from hr_timesheet where dayofweek='%s' and tgroup_id=%s order by hour_from desc", (dt_from.day_of_week,id))
47 for (hour_from,hour_to) in cr.fetchall():
48 if (hour_from<current_hour) and (todo>0):
49 m = min(hour_to, current_hour)
50 if (m-hour_from)>todo:
52 d1 = DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(hour_from)),int((hour_from%1) * 60))
53 d2 = DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(m)),int((m%1) * 60))
54 result.append((d1, d2))
55 current_hour = hour_from
57 dt_from -= DateTime.RelativeDateTime(days=1)
63 def interval_get(self, cr, uid, id, dt_from, hours, byday=True):
65 return [(dt_from,dt_from+DateTime.RelativeDateTime(hours=int(hours)*3))]
70 current_hour = dt_from.hour
71 while (todo>0) and maxrecur:
72 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))
73 for (hour_from,hour_to) in cr.fetchall():
74 if (hour_to>current_hour) and (todo>0):
75 m = max(hour_from, current_hour)
78 d1 = DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(m)),int((m%1) * 60))
79 d2 = DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(hour_to)),int((hour_to%1) * 60))
80 result.append((d1, d2))
81 current_hour = hour_to
83 dt_from += DateTime.RelativeDateTime(days=1)
91 class hr_employee_category(osv.osv):
92 _name = "hr.employee.category"
93 _description = "Employee Category"
96 'name' : fields.char("Category", size=64, required=True),
97 'parent_id': fields.many2one('hr.employee.category', 'Parent Category', select=True),
98 'child_ids': fields.one2many('hr.employee.category', 'parent_id', 'Child Categories')
101 def _check_recursion(self, cr, uid, ids):
104 cr.execute('select distinct parent_id from hr_employee_category where id in ('+','.join(map(str, ids))+')')
105 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
112 (_check_recursion, 'Error ! You cannot create recursive Categories.', ['parent_id'])
115 hr_employee_category()
117 class hr_employee(osv.osv):
118 _name = "hr.employee"
119 _description = "Employee"
122 'name' : fields.char("Employee", size=128, required=True),
123 'active' : fields.boolean('Active'),
124 'company_id': fields.many2one('res.company', 'Company'),
125 'user_id' : fields.many2one('res.users', 'Related User'),
127 'country_id' : fields.many2one('res.country', 'Nationality'),
128 'birthday' : fields.date("Birthday"),
129 'ssnid': fields.char('SSN No', size=32),
130 'sinid': fields.char('SIN No', size=32),
131 'otherid': fields.char('Other ID', size=32),
132 'gender': fields.selection([('',''),('male','Male'),('female','Female')], 'Gender'),
133 'marital': fields.selection([('married','Married'),('unmarried','Unmarried'),('divorced','Divorced'),('other','Other')],'Marital Status', size=32),
135 'address_id': fields.many2one('res.partner.address', 'Working Address'),
136 'address_home_id': fields.many2one('res.partner.address', 'Home Address'),
137 'work_phone': fields.char('Work Phone', size=32),
138 'work_email': fields.char('Work Email', size=128),
139 'work_location': fields.char('Office Location', size=32),
141 'notes': fields.text('Notes'),
142 'parent_id': fields.many2one('hr.employee', 'Manager', select=True),
143 'category_id' : fields.many2one('hr.employee.category', 'Category'),
144 'child_ids': fields.one2many('hr.employee', 'parent_id','Subordinates'),
147 'active' : lambda *a: True,
150 def _check_recursion(self, cr, uid, ids):
153 cr.execute('select distinct parent_id from hr_employee where id in ('+','.join(map(str, ids))+')')
154 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
161 (_check_recursion, 'Error ! You cannot create recursive Hierarchy of Employees.', ['parent_id'])
166 class hr_timesheet(osv.osv):
167 _name = "hr.timesheet"
168 _description = "Timesheet Line"
170 'name' : fields.char("Name", size=64, required=True),
171 'dayofweek': fields.selection([('0','Monday'),('1','Tuesday'),('2','Wednesday'),('3','Thursday'),('4','Friday'),('5','Saturday'),('6','Sunday')], 'Day of week'),
172 'date_from' : fields.date('Starting date'),
173 'hour_from' : fields.float('Work from', size=8, required=True),
174 'hour_to' : fields.float("Work to", size=8, required=True),
175 'tgroup_id' : fields.many2one("hr.timesheet.group", "Employee's timesheet group", select=True),
177 _order = 'dayofweek, hour_from'
181 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: