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
2006-12-07 13:41:40 +00:00
from osv import fields , osv
2011-03-10 13:18:27 +00:00
import logging
2010-10-25 10:05:42 +00:00
import addons
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 ) :
2010-10-27 12:49:59 +00:00
if not ids :
2010-10-08 13:22:47 +00:00
return [ ]
2010-11-19 13:48:01 +00:00
reads = self . read ( cr , uid , ids , [ ' name ' , ' parent_id ' ] , context = context )
2010-10-08 13:22:47 +00:00
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
2010-11-19 13:48:01 +00:00
def _name_get_fnc ( self , cr , uid , ids , prop , unknow_none , context = None ) :
res = self . name_get ( cr , uid , ids , context = context )
2010-10-08 13:22:47 +00:00
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 ) ,
2011-07-01 23:41:24 +00:00
' complete_name ' : fields . function ( _name_get_fnc , 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-12-15 17:24:55 +00:00
' name ' : fields . char ( ' Marital Status ' , size = 32 , required = True , translate = 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-11-19 13:48:01 +00:00
for job in self . browse ( cr , uid , ids , context = context ) :
2011-03-11 13:41:36 +00:00
nb_employees = len ( job . employee_ids or [ ] )
res [ job . id ] = {
' no_of_employee ' : nb_employees ,
' expected_employees ' : nb_employees + job . no_of_recruitment ,
}
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 ) ,
2011-07-01 23:41:24 +00:00
' expected_employees ' : fields . function ( _no_of_employee , string = ' Expected Employees ' , help = ' Required number of Employees in total for that job. ' , multi = " no_of_employee " , store = True ) ,
' no_of_employee ' : fields . function ( _no_of_employee , string = " No of Employee " , help = ' Number of employee with that job. ' , multi = " no_of_employee " , store = True ) ,
2011-03-11 13:41:36 +00:00
' no_of_recruitment ' : fields . float ( ' Expected in Recruitment ' ) ,
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
2011-03-11 13:41:36 +00:00
def on_change_expected_employee ( self , cr , uid , ids , no_of_recruitment , no_of_employee , context = None ) :
2010-10-14 10:43:56 +00:00
if context is None :
context = { }
2011-03-11 13:41:36 +00:00
return { ' value ' : { ' expected_employees ' : no_of_recruitment + no_of_employee } }
2010-10-14 10:43:56 +00:00
2010-07-21 12:39:48 +00:00
def job_old ( self , cr , uid , ids , * args ) :
2011-03-11 13:41:36 +00:00
self . write ( cr , uid , ids , { ' state ' : ' old ' , ' no_of_recruitment ' : 0 } )
2010-07-21 12:39:48 +00:00
return True
def job_recruitement ( self , cr , uid , ids , * args ) :
2011-03-11 13:41:36 +00:00
for job in self . browse ( cr , uid , ids ) :
no_of_recruitment = job . no_of_recruitment == 0 and 1 or job . no_of_recruitment
self . write ( cr , uid , [ job . id ] , { ' state ' : ' recruit ' , ' no_of_recruitment ' : no_of_recruitment } )
2010-07-21 12:39:48 +00:00
return True
def job_open ( self , cr , uid , ids , * args ) :
2011-03-11 13:41:36 +00:00
self . write ( cr , uid , ids , { ' state ' : ' open ' , ' no_of_recruitment ' : 0 } )
2010-07-21 12:39:48 +00:00
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. " ) ,
2011-03-02 10:44:41 +00:00
' bank_account_id ' : fields . many2one ( ' res.partner.bank ' , ' Bank Account Number ' , domain = " [( ' partner_id ' , ' = ' ,partner_id)] " , help = " Employee bank salary account " ) ,
2010-12-07 09:21:23 +00:00
' work_phone ' : fields . char ( ' Work Phone ' , size = 32 , readonly = False ) ,
2011-02-16 11:23:43 +00:00
' mobile_phone ' : fields . char ( ' Work Mobile ' , size = 32 , readonly = False ) ,
2010-12-07 09:21:23 +00:00
' work_email ' : fields . char ( ' Work E-mail ' , size = 240 ) ,
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 ' ) ,
2011-04-07 09:27:30 +00:00
' parent_id ' : fields . many2one ( ' hr.employee ' , ' Manager ' ) ,
2011-03-10 06:07:26 +00:00
' category_ids ' : fields . many2many ( ' hr.employee.category ' , ' employee_category_rel ' , ' emp_id ' , ' category_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 ' ) ,
2010-12-13 08:21:34 +00:00
' passport_id ' : fields . char ( ' Passport No ' , size = 64 )
2008-07-22 15:11:28 +00:00
}
2010-09-08 11:15:14 +00:00
2011-04-26 11:27:55 +00:00
def unlink ( self , cr , uid , ids , context = None ) :
resource_obj = self . pool . get ( ' resource.resource ' )
resource_ids = [ ]
for employee in self . browse ( cr , uid , ids , context = context ) :
resource = employee . resource_id
if resource :
resource_ids . append ( resource . id )
if resource_ids :
resource_obj . unlink ( cr , uid , resource_ids , context = context )
return super ( hr_employee , self ) . unlink ( cr , uid , ids , context = context )
2010-12-07 09:21:23 +00:00
def onchange_address_id ( self , cr , uid , ids , address , context = None ) :
if address :
address = self . pool . get ( ' res.partner.address ' ) . browse ( cr , uid , address , context = context )
2011-02-16 11:23:43 +00:00
return { ' value ' : { ' work_email ' : address . email , ' work_phone ' : address . phone , ' mobile_phone ' : address . mobile } }
2010-12-07 09:21:23 +00:00
return { ' value ' : { } }
2010-10-27 12:49:59 +00:00
def onchange_company ( self , cr , uid , ids , company , context = None ) :
2010-10-21 12:20:20 +00:00
address_id = False
2010-10-27 12:49:59 +00:00
if company :
2010-11-19 13:48:01 +00:00
company_id = self . pool . get ( ' res.company ' ) . browse ( cr , uid , company , context = context )
2010-10-21 12:20:20 +00:00
address = self . pool . get ( ' res.partner ' ) . address_get ( cr , uid , [ company_id . partner_id . id ] , [ ' default ' ] )
address_id = address and address [ ' default ' ] or False
return { ' value ' : { ' address_id ' : address_id } }
2010-09-08 11:15:14 +00:00
2011-03-11 10:54:49 +00:00
def onchange_department_id ( self , cr , uid , ids , department_id , context = None ) :
value = { ' parent_id ' : False }
if department_id :
department = self . pool . get ( ' hr.department ' ) . browse ( cr , uid , department_id )
value [ ' parent_id ' ] = department . manager_id . id
return { ' value ' : value }
2010-09-08 11:15:14 +00:00
def onchange_user ( self , cr , uid , ids , user_id , context = None ) :
2010-10-21 12:20:20 +00:00
work_email = False
if user_id :
2010-11-19 13:48:01 +00:00
work_email = self . pool . get ( ' res.users ' ) . browse ( cr , uid , user_id , context = context ) . user_email
2010-10-21 12:20:20 +00:00
return { ' value ' : { ' work_email ' : work_email } }
2010-10-08 13:22:47 +00:00
2010-05-21 13:05:52 +00:00
def _get_photo ( self , cr , uid , context = None ) :
2010-11-26 11:43:42 +00:00
photo_path = addons . get_module_resource ( ' hr ' , ' images ' , ' photo.png ' )
2010-10-28 09:45:32 +00:00
return open ( photo_path , ' 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 ,
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
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 ' ] ) ,
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 ' ) ,
2010-12-21 10:00:28 +00:00
' member_ids ' : fields . one2many ( ' hr.employee ' , ' department_id ' , ' Members ' , readonly = True ) ,
2010-07-21 12:39:48 +00:00
}
hr_department ( )
2011-03-10 13:18:27 +00:00
class res_users ( osv . osv ) :
_name = ' res.users '
_inherit = ' res.users '
def create ( self , cr , uid , data , context = None ) :
user_id = super ( res_users , self ) . create ( cr , uid , data , context = context )
data_obj = self . pool . get ( ' ir.model.data ' )
try :
data_id = data_obj . _get_id ( cr , uid , ' hr ' , ' ir_ui_view_sc_employee ' )
view_id = data_obj . browse ( cr , uid , data_id , context = context ) . res_id
self . pool . get ( ' ir.ui.view_sc ' ) . copy ( cr , uid , view_id , default = {
' user_id ' : user_id } , context = context )
except :
# Tolerate a missing shortcut. See product/product.py for similar code.
logging . getLogger ( ' orm ' ) . debug ( ' Skipped meetings shortcut for user " %s " ' , data . get ( ' name ' , ' <new ' ) )
2011-04-07 09:27:30 +00:00
2011-03-10 13:18:27 +00:00
return user_id
res_users ( )
2010-09-06 10:11:32 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: