[ADD] hr_evaluation: added wizard for functionality of reminders,improved code
[odoo/odoo.git] / addons / hr / hr.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 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 osv import fields, osv
23 from tools.translate import _
24
25 class hr_employee_category(osv.osv):
26     _name = "hr.employee.category"
27     _description = "Employee Category"
28
29     _columns = {
30         'name' : fields.char("Category", size=64, required=True),
31         'parent_id': fields.many2one('hr.employee.category', 'Parent Category', select=True),
32         'child_ids': fields.one2many('hr.employee.category', 'parent_id', 'Child Categories')
33     }
34
35     def _check_recursion(self, cr, uid, ids):
36         level = 100
37         while len(ids):
38             cr.execute('select distinct parent_id from hr_employee_category where id=ANY(%s)',(ids,))
39             ids = filter(None, map(lambda x:x[0], cr.fetchall()))
40             if not level:
41                 return False
42             level -= 1
43         return True
44
45     _constraints = [
46         (_check_recursion, 'Error ! You cannot create recursive Categories.', ['parent_id'])
47     ]
48
49 hr_employee_category()
50
51 class hr_employee_marital_status(osv.osv):
52     _name = "hr.employee.marital.status"
53     _description = "Employee Marital Status"
54     _columns = {
55         'name' : fields.char('Marital Status', size=30, required=True),
56         'description' : fields.text('Status Description'),
57     }
58 hr_employee_marital_status()
59
60 class hr_job(osv.osv):
61     def _no_of_employee(self, cr, uid, ids, name,args,context=None):
62         res = {}
63         for emp in self.browse(cr, uid, ids):
64             res[emp.id] = len(emp.employee_ids or [])
65         return res
66
67     _name = "hr.job"
68     _description = "Job Description"
69     _columns = {
70         'name': fields.char('Job Name', size=128, required=True, select=True),
71         'expected_employees':fields.integer('Expected Employees'),
72         'no_of_employee': fields.function(_no_of_employee, method=True, string='No of Employees', type='integer'),
73         'employee_ids':fields.one2many('hr.employee', 'job_id','Employees'),
74         'description': fields.text('Job Description'),
75         'requirements':fields.text('Requirements'),
76         'department_id':fields.many2one('hr.department','Department'),
77         'company_id': fields.many2one('res.company', 'Company'),
78         'state': fields.selection([('open','Open'),('old','Old'),('recruit','In Recruitement')], 'State', required=True),
79     }
80     _defaults = {
81         'expected_employees': lambda *a: 1,
82         'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr.job', context=c),
83         'state': lambda *args: 'open'
84     }
85 hr_job()
86
87 class hr_employee(osv.osv):
88     _name = "hr.employee"
89     _description = "Employee"
90     _inherits = {'resource.resource':"resource_id"}
91     _columns = {
92         'country_id' : fields.many2one('res.country', 'Nationality'),
93         'birthday' : fields.date("Birthday"),
94         'ssnid': fields.char('SSN No', size=32, help='Social Security Number'),
95         'sinid': fields.char('SIN No', size=32),
96         'otherid': fields.char('Other ID', size=32),
97         'gender': fields.selection([('male','Male'),('female','Female')], 'Gender'),
98         'marital': fields.many2one('hr.employee.marital.status', 'Marital Status'),
99         'bank_account': fields.char('Bank Account', size=56),
100         'partner_id' : fields.related('company_id', 'partner_id', type='many2one', relation='res.partner', readonly=True),
101         'department_id':fields.many2one('hr.department','Department'),
102         'address_id': fields.many2one('res.partner.address', 'Working Address'),
103         'address_home_id': fields.many2one('res.partner.address', 'Home Address'),
104         'work_phone': fields.related('address_id', 'phone', type='char', string='Work Phone'),
105         'work_email': fields.char('Work E-mail', size=240),
106 #        'work_email': fields.related('address_id', 'email', type='char', size=240, string='Work E-mail'),
107         'work_location': fields.char('Office Location', size=32),
108
109         'notes': fields.text('Notes'),
110         'parent_id': fields.many2one('hr.employee', 'Manager', select=True),
111         'category_id' : fields.many2one('hr.employee.category', 'Category'),
112         'child_ids': fields.one2many('hr.employee', 'parent_id','Subordinates'),
113         'resource_id': fields.many2one('resource.resource','Resource',ondelete='cascade'),
114         'coach_id':fields.many2one('res.users','Coach'),
115         'job_id':fields.many2one('hr.job', 'Job'),
116
117     }
118     _defaults = {
119         'active' : lambda *a: True,
120     }
121
122     def _check_recursion(self, cr, uid, ids):
123         level = 100
124         while len(ids):
125             cr.execute('select distinct parent_id from hr_employee where id =ANY(%s)',(ids,))
126             ids = filter(None, map(lambda x:x[0], cr.fetchall()))
127             if not level:
128                 return False
129             level -= 1
130         return True
131
132     _constraints = [
133         (_check_recursion, 'Error ! You cannot create recursive Hierarchy of Employees.', ['parent_id'])
134     ]
135
136 hr_employee()
137
138
139 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: