181d783d98dff270fcb2afe4d558a00e492e6dc5
[odoo/odoo.git] / addons / hr / hr.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from mx import DateTime
23 import time
24 import math
25
26 from osv import fields, osv
27 from tools.translate import _
28
29 class hr_employee_category(osv.osv):
30     _name = "hr.employee.category"
31     _description = "Employee Category"
32
33     _columns = {
34         'name' : fields.char("Category", size=64, required=True),
35         'parent_id': fields.many2one('hr.employee.category', 'Parent Category', select=True),
36         'child_ids': fields.one2many('hr.employee.category', 'parent_id', 'Child Categories')
37     }
38
39     def _check_recursion(self, cr, uid, ids):
40         level = 100
41         while len(ids):
42             cr.execute('select distinct parent_id from hr_employee_category where id in ('+','.join(map(str, ids))+')')
43             ids = filter(None, map(lambda x:x[0], cr.fetchall()))
44             if not level:
45                 return False
46             level -= 1
47         return True
48
49     _constraints = [
50         (_check_recursion, 'Error ! You cannot create recursive Categories.', ['parent_id'])
51     ]
52
53 hr_employee_category()
54
55 class hr_employee(osv.osv):
56     _name = "hr.employee"
57     _description = "Employee"
58     _inherits = {'resource.resource':"resource_id"}
59     _columns = {
60         'name' : fields.char("Employee's Name", size=128, required=True),
61         'active' : fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the employee record without removing it."),
62         'company_id': fields.many2one('res.company', 'Company'),
63         'user_id' : fields.many2one('res.users', 'Related User', help='Related user name for an employee to manage his access rights.'),
64
65         'country_id' : fields.many2one('res.country', 'Nationality'),
66         'birthday' : fields.date("Birthday"),
67         'ssnid': fields.char('SSN No', size=32, help='Social Security Number'),
68         'sinid': fields.char('SIN No', size=32),
69         'otherid': fields.char('Other ID', size=32),
70         'gender': fields.selection([('',''),('male','Male'),('female','Female')], 'Gender'),
71         'marital': fields.selection([('married','Married'),('unmarried','Unmarried'),('divorced','Divorced'),('other','Other')],'Marital Status', size=32),
72
73         'address_id': fields.many2one('res.partner.address', 'Working Address'),
74         'address_home_id': fields.many2one('res.partner.address', 'Home Address'),
75         'work_phone': fields.char('Work Phone', size=32),
76         'work_email': fields.char('Work Email', size=128),
77         'work_location': fields.char('Office Location', size=32),
78
79         'notes': fields.text('Notes'),
80         'parent_id': fields.many2one('hr.employee', 'Manager', select=True),
81         'category_id' : fields.many2one('hr.employee.category', 'Category'),
82         'child_ids': fields.one2many('hr.employee', 'parent_id','Subordinates'),
83         'resource_id': fields.many2one('resource.resource','Resource',ondelete='cascade'),
84     }
85     _defaults = {
86         'active' : lambda *a: True,
87     }
88
89     def _check_recursion(self, cr, uid, ids):
90         level = 100
91         while len(ids):
92             cr.execute('select distinct parent_id from hr_employee where id in ('+','.join(map(str, ids))+')')
93             ids = filter(None, map(lambda x:x[0], cr.fetchall()))
94             if not level:
95                 return False
96             level -= 1
97         return True
98
99     _constraints = [
100         (_check_recursion, 'Error ! You cannot create recursive Hierarchy of Employees.', ['parent_id'])
101     ]
102
103 hr_employee()
104 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: