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-08-12 04:17:18 +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 ) :
2010-10-08 13:22:47 +00:00
def name_get ( self , cr , uid , ids , context = None ) :
if not len ( ids ) :
return [ ]
reads = self . read ( cr , uid , ids , [ ' name ' , ' parent_id ' ] , context )
res = [ ]
for record in reads :
name = record [ ' name ' ]
if record [ ' parent_id ' ] :
name = record [ ' parent_id ' ] [ 1 ] + ' / ' + name
res . append ( ( record [ ' id ' ] , name ) )
return res
def _name_get_fnc ( self , cr , uid , ids , prop , unknow_none , context ) :
res = self . name_get ( cr , uid , ids , context )
return dict ( res )
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 ) ,
2010-10-08 13:22:47 +00:00
' complete_name ' : fields . function ( _name_get_fnc , method = True , type = " char " , string = ' Name ' ) ,
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
2010-07-07 07:04:42 +00:00
def _check_recursion ( self , cr , uid , ids , context = None ) :
2009-01-02 09:54:21 +00:00
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-07 07:04:42 +00:00
' name ' : fields . char ( ' Marital Status ' , size = 32 , required = True ) ,
2010-07-03 10:21:52 +00:00
' description ' : fields . text ( ' Status Description ' ) ,
2010-02-16 07:02:46 +00:00
}
2010-07-07 07:04:42 +00:00
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 = { }
2010-10-15 16:53:15 +00:00
for job in self . browse ( cr , uid , ids , context ) :
res [ job . id ] = len ( job . employee_ids or [ ] )
return res
def _no_of_recruitement ( self , cr , uid , ids , name , args , context = None ) :
res = { }
for job in self . browse ( cr , uid , ids , context ) :
res [ job . id ] = job . expected_employees - job . no_of_employee
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-10-15 16:53:15 +00:00
' expected_employees ' : fields . integer ( ' Expected Employees ' , help = ' Required number of Employees in total for that job. ' ) ,
' no_of_employee ' : fields . function ( _no_of_employee , method = True , string = " No of Employee " , help = ' Number of employee with that job. ' ) ,
' no_of_recruitment ' : fields . function ( _no_of_recruitement , method = True , string = ' Expected in Recruitment ' , readonly = True ) ,
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-10-12 21:59:40 +00:00
' state ' : fields . selection ( [ ( ' open ' , ' In Position ' ) , ( ' old ' , ' Old ' ) , ( ' recruit ' , ' In Recruitement ' ) ] , ' State ' , readonly = True , 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-10-14 10:43:56 +00:00
' state ' : ' open ' ,
2010-02-28 19:44:19 +00:00
}
2010-04-13 05:21:13 +00:00
2010-10-15 06:01:58 +00:00
def on_change_expected_employee ( self , cr , uid , ids , expected_employee , no_of_employee , context = None ) :
2010-10-14 10:43:56 +00:00
if context is None :
context = { }
result = { }
if expected_employee :
2010-10-15 06:01:58 +00:00
result [ ' no_of_recruitment ' ] = expected_employee - no_of_employee
2010-10-14 10:43:56 +00:00
return { ' value ' : result }
2010-07-21 12:39:48 +00:00
def job_old ( self , cr , uid , ids , * args ) :
self . write ( cr , uid , ids , { ' state ' : ' old ' } )
return True
def job_recruitement ( self , cr , uid , ids , * args ) :
self . write ( cr , uid , ids , { ' state ' : ' recruit ' } )
return True
def job_open ( self , cr , uid , ids , * args ) :
self . write ( cr , uid , ids , { ' state ' : ' open ' } )
return True
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 ' ) ,
2010-09-06 10:11:32 +00:00
' birthday ' : fields . date ( " Date of Birth " ) ,
2009-12-22 13:08:10 +00:00
' ssnid ' : fields . char ( ' SSN No ' , size = 32 , help = ' Social Security Number ' ) ,
2010-07-07 07:04:42 +00:00
' sinid ' : fields . char ( ' SIN No ' , size = 32 , help = " Social Insurance Number " ) ,
2010-09-11 13:29:00 +00:00
' identification_id ' : fields . char ( ' Identification No ' , 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-07-21 12:39:48 +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-10-04 14:31:37 +00:00
' partner_id ' : fields . related ( ' address_home_id ' , ' partner_id ' , type = ' many2one ' , relation = ' res.partner ' , readonly = True , help = " Partner that is related to the current employee. Accounting transaction will be written on this partner belongs to employee. " ) ,
2010-10-08 16:01:55 +00:00
' bank_account_id ' : fields . many2one ( ' res.partner.bank ' , ' Bank Account ' , domain = " [( ' partner_id ' , ' = ' ,partner_id)] " , help = " Employee bank salary account " ) ,
2010-10-08 13:22:47 +00:00
' work_phone ' : fields . related ( ' address_id ' , ' phone ' , type = ' char ' , size = 32 , string = ' Work Phone ' , readonly = True ) ,
2010-09-06 10:11:32 +00:00
' work_email ' : fields . related ( ' address_id ' , ' email ' , type = ' char ' , size = 240 , string = ' Work E-mail ' ) ,
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 ' ) ,
2010-09-08 11:15:14 +00:00
' parent_id ' : fields . related ( ' department_id ' , ' manager_id ' , relation = ' hr.employee ' , string = ' Manager ' , type = ' many2one ' , store = True , select = True , readonly = True , help = " It is linked with manager of Department " ) ,
2010-07-21 12:39:48 +00:00
' category_ids ' : fields . many2many ( ' hr.employee.category ' , ' employee_category_rel ' , ' category_id ' , ' emp_id ' , ' Category ' ) ,
2010-07-03 10:21:52 +00:00
' child_ids ' : fields . one2many ( ' hr.employee ' , ' parent_id ' , ' Subordinates ' ) ,
2010-08-12 19:29:33 +00:00
' resource_id ' : fields . many2one ( ' resource.resource ' , ' Resource ' , ondelete = ' cascade ' , required = True ) ,
2010-07-21 12:39:48 +00:00
' coach_id ' : fields . many2one ( ' hr.employee ' , ' Coach ' ) ,
2010-05-21 13:05:52 +00:00
' job_id ' : fields . many2one ( ' hr.job ' , ' Job ' ) ,
2010-10-07 07:31:31 +00:00
' photo ' : fields . binary ( ' Photo ' ) ,
' passport_id ' : fields . char ( ' Passport ' , size = 64 )
2008-07-22 15:11:28 +00:00
}
2010-09-08 11:15:14 +00:00
def onchange_company ( self , cr , uid , ids , company , context = None ) :
company_id = self . pool . get ( ' res.company ' ) . browse ( cr , uid , company )
for address in company_id . partner_id . address :
return { ' value ' : { ' address_id ' : address . id } }
2010-10-08 13:22:47 +00:00
return { ' value ' : { ' address_id ' : False } }
2010-09-08 11:15:14 +00:00
def onchange_department ( self , cr , uid , ids , department_id , context = None ) :
2010-10-08 13:22:47 +00:00
if not department_id :
return { ' value ' : { ' parent_id ' : False } }
manager = self . pool . get ( ' hr.department ' ) . browse ( cr , uid , department_id ) . manager_id
return { ' value ' : { ' parent_id ' : manager and manager . id or False } }
2010-09-08 11:15:14 +00:00
def onchange_user ( self , cr , uid , ids , user_id , context = None ) :
2010-10-08 13:22:47 +00:00
if not user_id :
return { ' value ' : { ' work_email ' : False } }
2010-09-08 11:15:14 +00:00
mail = self . pool . get ( ' res.users ' ) . browse ( cr , uid , user_id )
2010-10-08 13:22:47 +00:00
return { ' value ' : { ' work_email ' : mail . user_email } }
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 ' )
2010-10-08 13:22:47 +00:00
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 ,
2010-09-06 10:11:32 +00:00
' address_id ' : lambda self , cr , uid , c : self . pool . get ( ' res.partner.address ' ) . browse ( cr , uid , uid , c ) . partner_id . id
2008-07-22 15:11:28 +00:00
}
2010-01-12 05:32:48 +00:00
2010-07-07 07:04:42 +00:00
def _check_recursion ( self , cr , uid , ids , context = None ) :
2009-01-02 09:54:21 +00:00
level = 100
while len ( ids ) :
2010-08-12 06:02:33 +00:00
cr . execute ( ' SELECT DISTINCT parent_id FROM hr_employee WHERE id IN %s AND parent_id!=id ' , ( 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
2010-08-14 06:31:32 +00:00
def _check_department_id ( self , cr , uid , ids , context = None ) :
for emp in self . browse ( cr , uid , ids , context = context ) :
if emp . department_id . manager_id and emp . id == emp . department_id . manager_id . id :
return False
return True
2009-01-02 09:54:21 +00:00
_constraints = [
2010-08-14 06:31:32 +00:00
( _check_recursion , ' Error ! You cannot create recursive Hierarchy of Employees. ' , [ ' parent_id ' ] ) ,
( _check_department_id , ' Error ! You cannot select a department for which the employee is the manager. ' , [ ' department_id ' ] ) ,
2009-01-02 09:54:21 +00:00
]
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
2010-07-21 12:39:48 +00:00
class hr_department ( osv . osv ) :
_description = " Department "
_inherit = ' hr.department '
_columns = {
' manager_id ' : fields . many2one ( ' hr.employee ' , ' Manager ' ) ,
' member_ids ' : fields . one2many ( ' hr.employee ' , ' department_id ' , ' Members ' ) ,
}
hr_department ( )
2010-09-06 10:11:32 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: