2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2007-03-07 18:49:32 +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>).
2007-03-07 18:49:32 +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.
2007-03-07 18:49:32 +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.
2007-03-07 18:49:32 +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/>.
2007-03-07 18:49:32 +00:00
#
##############################################################################
2010-04-14 09:46:19 +00:00
import time
2007-03-07 18:49:32 +00:00
2007-03-07 18:10:55 +00:00
from osv import fields , osv
class hr_employee ( osv . osv ) :
2008-07-22 15:11:28 +00:00
_name = " hr.employee "
_description = " Employee "
_inherit = " hr.employee "
2010-08-19 09:38:02 +00:00
def _get_latest_contract ( self , cr , uid , ids , field_name , args , context = None ) :
res = { }
obj_contract = self . pool . get ( ' hr.contract ' )
for emp in self . browse ( cr , uid , ids , context = context ) :
contract_ids = obj_contract . search ( cr , uid , [ ( ' employee_id ' , ' = ' , emp . id ) , ] , order = ' date_start ' , context = context )
if contract_ids :
res [ emp . id ] = contract_ids [ - 1 : ] [ 0 ]
else :
res [ emp . id ] = False
return res
2008-07-22 15:11:28 +00:00
_columns = {
2010-06-12 22:33:23 +00:00
' manager ' : fields . boolean ( ' Is a Manager ' ) ,
2010-04-14 09:46:19 +00:00
' medic_exam ' : fields . date ( ' Medical Examination Date ' ) ,
' place_of_birth ' : fields . char ( ' Place of Birth ' , size = 30 ) ,
' children ' : fields . integer ( ' Number of Children ' ) ,
2010-06-12 22:33:23 +00:00
' vehicle ' : fields . char ( ' Company Vehicle ' , size = 64 ) ,
2010-04-14 09:46:19 +00:00
' vehicle_distance ' : fields . integer ( ' Home-Work Distance ' , help = " In kilometers " ) ,
' contract_ids ' : fields . one2many ( ' hr.contract ' , ' employee_id ' , ' Contracts ' ) ,
2010-08-19 09:38:02 +00:00
' contract_id ' : fields . function ( _get_latest_contract , method = True , string = ' Contract ' , type = ' many2one ' , relation = " hr.contract " , help = ' Latest contract of the employee ' ) ,
}
2007-03-07 18:10:55 +00:00
hr_employee ( )
2011-03-03 12:49:03 +00:00
class hr_passport ( osv . osv ) :
"""
Employee Passport
Passport based Contracts for Employees
"""
2011-03-08 06:36:37 +00:00
_name = ' hr.passport '
2011-03-03 12:49:03 +00:00
_description = ' Passport Detail '
_columns = {
2011-03-08 06:36:37 +00:00
' employee_id ' : fields . many2one ( ' hr.employee ' , ' Employee ' , required = True ) ,
' name ' : fields . char ( ' Passport No ' , size = 64 , required = True , readonly = False ) ,
' country_id ' : fields . many2one ( ' res.country ' , ' Country of Issue ' , required = True ) ,
' address_id ' : fields . many2one ( ' res.partner.address ' , ' Address ' , required = False ) ,
' date_issue ' : fields . date ( ' Passport Issue Date ' , required = True ) ,
' date_expire ' : fields . date ( ' Passport Expire Date ' , required = True ) ,
' note ' : fields . text ( ' Description ' ) ,
2011-03-03 12:49:03 +00:00
' contracts_ids ' : fields . one2many ( ' hr.contract ' , ' passport_id ' , ' Contracts ' , required = False , readonly = True ) ,
}
2011-03-08 06:36:37 +00:00
_sql_constraints = [
( ' passport_no_uniq ' , ' unique (employee_id, name) ' , ' The Passport No must be unique ! ' ) ,
]
2011-03-03 12:49:03 +00:00
hr_passport ( )
2007-03-07 18:10:55 +00:00
#Contract wage type period name
2011-03-22 10:35:31 +00:00
#Fix me: i think we shoul remove this object as we need not the hr.contract.wage.type object
#class hr_contract_wage_type_period(osv.osv):
# _name='hr.contract.wage.type.period'
# _description='Wage Period'
# _columns = {
# 'name': fields.char('Period Name', size=50, required=True, select=True),
# 'factor_days': fields.float('Hours in the period', digits=(12,4), required=True, help='This field is used by the timesheet system to compute the price of an hour of work wased on the contract of the employee')
# }
# _defaults = {
# 'factor_days': 168.0
# }
#hr_contract_wage_type_period()
2007-03-07 18:10:55 +00:00
#Contract wage type (hourly, daily, monthly, ...)
2011-03-07 11:28:17 +00:00
#class hr_contract_wage_type(osv.osv):
# _name = 'hr.contract.wage.type'
# _description = 'Wage Type'
# _columns = {
# 'name': fields.char('Wage Type Name', size=50, required=True, select=True),
# 'period_id': fields.many2one('hr.contract.wage.type.period', 'Wage Period', required=True),
# 'factor_type': fields.float('Factor for hour cost', digits=(12,4), required=True, help='This field is used by the timesheet system to compute the price of an hour of work based on the contract of the employee')
# }
# _defaults = {
# 'factor_type': 1.8
# }
#hr_contract_wage_type()
2007-03-07 18:10:55 +00:00
2010-03-05 17:36:19 +00:00
class hr_contract_type ( osv . osv ) :
_name = ' hr.contract.type '
_description = ' Contract Type '
_columns = {
2010-04-14 09:46:19 +00:00
' name ' : fields . char ( ' Contract Type ' , size = 32 , required = True ) ,
2010-03-05 17:36:19 +00:00
}
hr_contract_type ( )
2007-03-07 18:10:55 +00:00
class hr_contract ( osv . osv ) :
2008-07-22 15:11:28 +00:00
_name = ' hr.contract '
_description = ' Contract '
_columns = {
2010-04-14 09:46:19 +00:00
' name ' : fields . char ( ' Contract Reference ' , size = 32 , required = True ) ,
2010-03-08 05:14:12 +00:00
' employee_id ' : fields . many2one ( ' hr.employee ' , " Employee " , required = True ) ,
2010-09-01 06:06:34 +00:00
' department_id ' : fields . related ( ' employee_id ' , ' department_id ' , type = ' many2one ' , relation = ' hr.department ' , string = " Department " , readonly = True ) ,
2010-09-14 13:44:35 +00:00
' type_id ' : fields . many2one ( ' hr.contract.type ' , " Contract Type " , required = True ) ,
2010-03-08 05:14:12 +00:00
' job_id ' : fields . many2one ( ' hr.job ' , ' Job Title ' ) ,
' date_start ' : fields . date ( ' Start Date ' , required = True ) ,
' date_end ' : fields . date ( ' End Date ' ) ,
2010-09-15 13:50:27 +00:00
' trial_date_start ' : fields . date ( ' Trial Start Date ' ) ,
' trial_date_end ' : fields . date ( ' Trial End Date ' ) ,
2010-05-10 12:21:19 +00:00
' working_hours ' : fields . many2one ( ' resource.calendar ' , ' Working Schedule ' ) ,
2011-03-02 09:34:07 +00:00
' wage ' : fields . float ( ' Wage ' , digits = ( 16 , 2 ) , required = True , help = " Basic Salary of the employee " ) ,
2010-03-05 17:36:19 +00:00
' advantages ' : fields . text ( ' Advantages ' ) ,
2010-03-08 05:14:12 +00:00
' notes ' : fields . text ( ' Notes ' ) ,
2011-03-03 12:49:03 +00:00
' permit_no ' : fields . char ( ' Work Permit No ' , size = 256 , required = False , readonly = False ) ,
2011-03-08 06:36:37 +00:00
' passport_id ' : fields . many2one ( ' hr.passport ' , ' Passport ' , required = False ) ,
2011-03-03 12:49:03 +00:00
' visa_no ' : fields . char ( ' Visa No ' , size = 64 , required = False , readonly = False ) ,
' visa_expire ' : fields . date ( ' Visa Expire Date ' ) ,
2010-08-26 04:52:04 +00:00
}
2008-07-22 15:11:28 +00:00
_defaults = {
2010-11-04 12:42:42 +00:00
' date_start ' : lambda * a : time . strftime ( " % Y- % m- %d " ) ,
2010-08-26 04:52:04 +00:00
}
2010-07-03 10:21:52 +00:00
2010-12-21 13:26:41 +00:00
def _check_dates ( self , cr , uid , ids , context = None ) :
for contract in self . read ( cr , uid , ids , [ ' date_start ' , ' date_end ' ] , context = context ) :
2010-12-22 05:21:47 +00:00
if contract [ ' date_start ' ] and contract [ ' date_end ' ] and contract [ ' date_start ' ] > contract [ ' date_end ' ] :
return False
2010-12-21 13:26:41 +00:00
return True
_constraints = [
( _check_dates , ' Error! contract start-date must be lower then contract end-date. ' , [ ' date_start ' , ' date_end ' ] )
]
2007-03-07 18:10:55 +00:00
hr_contract ( )
2011-03-03 12:49:03 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: