2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2010-01-12 05:32:48 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# 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
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-01-12 05:32:48 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
2010-05-21 13:05:52 +00:00
|
|
|
import os
|
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
from osv import fields, osv
|
2010-05-21 13:05:52 +00:00
|
|
|
import tools
|
2008-07-08 08:13:12 +00:00
|
|
|
from tools.translate import _
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
class hr_employee_category(osv.osv):
|
2008-07-22 15:11:28 +00:00
|
|
|
_name = "hr.employee.category"
|
|
|
|
_description = "Employee Category"
|
|
|
|
_columns = {
|
2010-07-03 10:21:52 +00:00
|
|
|
'name': fields.char("Category", size=64, required=True),
|
2009-01-27 11:15:46 +00:00
|
|
|
'parent_id': fields.many2one('hr.employee.category', 'Parent Category', select=True),
|
|
|
|
'child_ids': fields.one2many('hr.employee.category', 'parent_id', 'Child Categories')
|
2008-07-22 15:11:28 +00:00
|
|
|
}
|
2010-01-12 05:32:48 +00:00
|
|
|
|
2009-01-02 09:54:21 +00:00
|
|
|
def _check_recursion(self, cr, uid, ids):
|
|
|
|
level = 100
|
|
|
|
while len(ids):
|
2010-07-03 10:21:52 +00:00
|
|
|
cr.execute('select distinct parent_id from hr_employee_category where id IN %s', (tuple(ids), ))
|
2009-01-02 09:54:21 +00:00
|
|
|
ids = filter(None, map(lambda x:x[0], cr.fetchall()))
|
|
|
|
if not level:
|
|
|
|
return False
|
|
|
|
level -= 1
|
|
|
|
return True
|
2010-01-12 05:32:48 +00:00
|
|
|
|
2009-01-02 09:54:21 +00:00
|
|
|
_constraints = [
|
|
|
|
(_check_recursion, 'Error ! You cannot create recursive Categories.', ['parent_id'])
|
|
|
|
]
|
2010-01-12 05:32:48 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
hr_employee_category()
|
|
|
|
|
2010-02-16 07:02:46 +00:00
|
|
|
class hr_employee_marital_status(osv.osv):
|
|
|
|
_name = "hr.employee.marital.status"
|
|
|
|
_description = "Employee Marital Status"
|
|
|
|
_columns = {
|
2010-07-03 10:21:52 +00:00
|
|
|
'name': fields.char('Marital Status', size=30, required=True),
|
|
|
|
'description': fields.text('Status Description'),
|
2010-02-16 07:02:46 +00:00
|
|
|
}
|
|
|
|
hr_employee_marital_status()
|
|
|
|
|
2010-02-28 19:44:19 +00:00
|
|
|
class hr_job(osv.osv):
|
2010-07-03 10:21:52 +00:00
|
|
|
|
|
|
|
def _no_of_employee(self, cr, uid, ids, name, args, context=None):
|
2010-02-18 10:13:12 +00:00
|
|
|
res = {}
|
|
|
|
for emp in self.browse(cr, uid, ids):
|
2010-02-28 19:44:19 +00:00
|
|
|
res[emp.id] = len(emp.employee_ids or [])
|
2010-02-18 10:13:12 +00:00
|
|
|
return res
|
|
|
|
|
2010-02-28 19:44:19 +00:00
|
|
|
_name = "hr.job"
|
|
|
|
_description = "Job Description"
|
2010-02-18 10:13:12 +00:00
|
|
|
_columns = {
|
2010-02-28 19:44:19 +00:00
|
|
|
'name': fields.char('Job Name', size=128, required=True, select=True),
|
2010-07-03 10:21:52 +00:00
|
|
|
'expected_employees': fields.integer('Expected Employees', help='Required number of Employees'),
|
2010-06-30 12:45:20 +00:00
|
|
|
'no_of_employee': fields.function(_no_of_employee, method=True, string='No of Employees', type='integer', help='Number of Employees selected'),
|
2010-07-03 10:21:52 +00:00
|
|
|
'employee_ids': fields.one2many('hr.employee', 'job_id', 'Employees'),
|
2010-02-18 10:13:12 +00:00
|
|
|
'description': fields.text('Job Description'),
|
2010-07-03 10:21:52 +00:00
|
|
|
'requirements': fields.text('Requirements'),
|
|
|
|
'department_id': fields.many2one('hr.department', 'Department'),
|
2010-02-28 19:44:19 +00:00
|
|
|
'company_id': fields.many2one('res.company', 'Company'),
|
2010-07-03 10:21:52 +00:00
|
|
|
'state': fields.selection([('open', 'Open'),('old', 'Old'),('recruit', 'In Recruitement')], 'State', required=True),
|
2010-02-28 19:44:19 +00:00
|
|
|
}
|
2010-02-18 10:13:12 +00:00
|
|
|
_defaults = {
|
2010-07-03 10:21:52 +00:00
|
|
|
'expected_employees': 1,
|
2010-02-28 19:44:19 +00:00
|
|
|
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr.job', context=c),
|
2010-07-03 10:21:52 +00:00
|
|
|
'state': 'open'
|
2010-02-28 19:44:19 +00:00
|
|
|
}
|
2010-04-13 05:21:13 +00:00
|
|
|
|
2010-02-28 19:44:19 +00:00
|
|
|
hr_job()
|
2010-02-18 10:13:12 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
class hr_employee(osv.osv):
|
2008-07-22 15:11:28 +00:00
|
|
|
_name = "hr.employee"
|
|
|
|
_description = "Employee"
|
2010-07-03 10:21:52 +00:00
|
|
|
_inherits = {'resource.resource': "resource_id"}
|
2008-07-22 15:11:28 +00:00
|
|
|
_columns = {
|
2010-07-03 10:21:52 +00:00
|
|
|
'country_id': fields.many2one('res.country', 'Nationality'),
|
|
|
|
'birthday': fields.date("Birthday"),
|
2009-12-22 13:08:10 +00:00
|
|
|
'ssnid': fields.char('SSN No', size=32, help='Social Security Number'),
|
2008-08-27 20:53:10 +00:00
|
|
|
'sinid': fields.char('SIN No', size=32),
|
|
|
|
'otherid': fields.char('Other ID', size=32),
|
2010-07-03 10:21:52 +00:00
|
|
|
'gender': fields.selection([('male', 'Male'),('female', 'Female')], 'Gender'),
|
2010-02-16 07:02:46 +00:00
|
|
|
'marital': fields.many2one('hr.employee.marital.status', 'Marital Status'),
|
2010-03-05 17:36:19 +00:00
|
|
|
'bank_account': fields.char('Bank Account', size=56),
|
2010-07-03 10:21:52 +00:00
|
|
|
'partner_id': fields.related('company_id', 'partner_id', type='many2one', relation='res.partner', readonly=True),
|
2010-03-05 17:51:47 +00:00
|
|
|
'department_id':fields.many2one('hr.department','Department'),
|
2008-10-29 15:16:39 +00:00
|
|
|
'address_id': fields.many2one('res.partner.address', 'Working Address'),
|
2009-02-01 17:06:59 +00:00
|
|
|
'address_home_id': fields.many2one('res.partner.address', 'Home Address'),
|
2010-04-07 09:54:57 +00:00
|
|
|
'work_phone': fields.related('address_id', 'phone', type='char', string='Work Phone', readonly=True),
|
|
|
|
'work_email': fields.related('address_id', 'email', type='char', size=240, string='Work E-mail', readonly=True),
|
2008-08-27 20:53:10 +00:00
|
|
|
'work_location': fields.char('Office Location', size=32),
|
2008-07-22 15:11:28 +00:00
|
|
|
'notes': fields.text('Notes'),
|
2008-08-27 20:53:10 +00:00
|
|
|
'parent_id': fields.many2one('hr.employee', 'Manager', select=True),
|
2010-07-03 10:21:52 +00:00
|
|
|
'category_id': fields.many2one('hr.employee.category', 'Category'),
|
|
|
|
'child_ids': fields.one2many('hr.employee', 'parent_id', 'Subordinates'),
|
2010-06-16 11:51:39 +00:00
|
|
|
'resource_id': fields.many2one('resource.resource', 'Resource', ondelete='cascade'),
|
|
|
|
'coach_id': fields.many2one('res.users', 'Coach'),
|
2010-05-21 13:05:52 +00:00
|
|
|
'job_id': fields.many2one('hr.job', 'Job'),
|
|
|
|
'photo': fields.binary('Photo')
|
2008-07-22 15:11:28 +00:00
|
|
|
}
|
2010-05-21 13:05:52 +00:00
|
|
|
|
|
|
|
def _get_photo(self, cr, uid, context=None):
|
|
|
|
return open(os.path.join(
|
|
|
|
tools.config['addons_path'], 'hr/image', 'photo.png'),
|
|
|
|
'rb') .read().encode('base64')
|
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
_defaults = {
|
2010-07-03 10:21:52 +00:00
|
|
|
'active': 1,
|
2010-05-21 13:05:52 +00:00
|
|
|
'photo': _get_photo,
|
2008-07-22 15:11:28 +00:00
|
|
|
}
|
2010-01-12 05:32:48 +00:00
|
|
|
|
2009-01-02 09:54:21 +00:00
|
|
|
def _check_recursion(self, cr, uid, ids):
|
|
|
|
level = 100
|
|
|
|
while len(ids):
|
2010-06-10 13:34:19 +00:00
|
|
|
cr.execute('select distinct parent_id from hr_employee where id IN %s',(tuple(ids),))
|
2009-01-02 09:54:21 +00:00
|
|
|
ids = filter(None, map(lambda x:x[0], cr.fetchall()))
|
|
|
|
if not level:
|
|
|
|
return False
|
|
|
|
level -= 1
|
|
|
|
return True
|
2010-01-12 05:32:48 +00:00
|
|
|
|
2009-01-02 09:54:21 +00:00
|
|
|
_constraints = [
|
|
|
|
(_check_recursion, 'Error ! You cannot create recursive Hierarchy of Employees.', ['parent_id'])
|
|
|
|
]
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2010-01-12 05:32:48 +00:00
|
|
|
hr_employee()
|
2010-02-18 10:13:12 +00:00
|
|
|
|
2009-03-06 22:18:24 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|