2010-02-28 20:36:51 +00:00
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# 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.
#
# 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
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
2010-08-02 09:57:42 +00:00
import time
2010-06-24 19:53:32 +00:00
import tools
2010-08-02 09:57:42 +00:00
2012-08-06 01:27:17 +00:00
from base_status . base_stage import base_stage
2012-08-23 15:32:03 +00:00
from datetime import datetime
2010-05-12 08:36:32 +00:00
from osv import fields , osv
2010-06-24 19:53:32 +00:00
from tools . translate import _
2012-10-09 15:54:20 +00:00
from tools import html2plaintext
2010-02-28 20:36:51 +00:00
AVAILABLE_STATES = [
2010-05-14 09:29:24 +00:00
( ' draft ' , ' New ' ) ,
2010-02-28 20:36:51 +00:00
( ' cancel ' , ' Refused ' ) ,
2010-05-14 09:29:24 +00:00
( ' open ' , ' In Progress ' ) ,
2012-04-27 09:51:37 +00:00
( ' pending ' , ' Pending ' ) ,
( ' done ' , ' Hired ' )
2010-02-28 20:36:51 +00:00
]
AVAILABLE_PRIORITIES = [
2011-08-18 19:30:44 +00:00
( ' ' , ' ' ) ,
2010-05-14 09:29:24 +00:00
( ' 5 ' , ' Not Good ' ) ,
( ' 4 ' , ' On Average ' ) ,
( ' 3 ' , ' Good ' ) ,
( ' 2 ' , ' Very Good ' ) ,
2010-05-12 08:36:32 +00:00
( ' 1 ' , ' Excellent ' )
2010-02-28 20:36:51 +00:00
]
2011-08-18 19:30:44 +00:00
class hr_recruitment_source ( osv . osv ) :
""" Sources of HR Recruitment """
_name = " hr.recruitment.source "
_description = " Source of Applicants "
_columns = {
' name ' : fields . char ( ' Source Name ' , size = 64 , required = True , translate = True ) ,
}
2010-05-11 13:54:14 +00:00
class hr_recruitment_stage ( osv . osv ) :
""" Stage of HR Recruitment """
_name = " hr.recruitment.stage "
_description = " Stage of Recruitment "
2010-07-20 07:17:40 +00:00
_order = ' sequence '
2010-05-11 13:54:14 +00:00
_columns = {
2010-05-12 05:56:48 +00:00
' name ' : fields . char ( ' Name ' , size = 64 , required = True , translate = True ) ,
' sequence ' : fields . integer ( ' Sequence ' , help = " Gives the sequence order when displaying a list of stages. " ) ,
2012-07-13 10:17:51 +00:00
' department_id ' : fields . many2one ( ' hr.department ' , ' Specific to a Department ' , help = " Stages of the recruitment process may be different per department. If this stage is common to all departments, keep this field empty. " ) ,
2012-10-12 11:42:58 +00:00
' state ' : fields . selection ( AVAILABLE_STATES , ' Status ' , required = True , help = " The related status for the stage. The status of your document will automatically change according to the selected stage. Example, a stage is related to the status ' Close ' , when your document reach this stage, it will be automatically closed. " ) ,
2012-05-22 14:48:06 +00:00
' fold ' : fields . boolean ( ' Hide in views if empty ' , help = " This stage is not visible, for example in status bar or kanban view, when there are no records in that stage to display. " ) ,
' requirements ' : fields . text ( ' Requirements ' ) ,
2010-05-11 13:54:14 +00:00
}
_defaults = {
' sequence ' : 1 ,
2012-04-18 07:57:30 +00:00
' state ' : ' draft ' ,
2012-05-22 14:48:06 +00:00
' fold ' : False ,
2010-05-11 13:54:14 +00:00
}
2010-02-28 20:36:51 +00:00
2010-07-26 06:15:27 +00:00
class hr_recruitment_degree ( osv . osv ) :
""" Degree of HR Recruitment """
_name = " hr.recruitment.degree "
_description = " Degree of Recruitment "
_columns = {
' name ' : fields . char ( ' Name ' , size = 64 , required = True , translate = True ) ,
' sequence ' : fields . integer ( ' Sequence ' , help = " Gives the sequence order when displaying a list of degrees. " ) ,
}
_defaults = {
' sequence ' : 1 ,
}
2011-08-05 05:20:25 +00:00
_sql_constraints = [
( ' name_uniq ' , ' unique (name) ' , ' The name of the Degree of Recruitment must be unique! ' )
]
2010-07-26 06:15:27 +00:00
2012-05-29 14:03:14 +00:00
class hr_applicant ( base_stage , osv . Model ) :
2010-02-28 20:36:51 +00:00
_name = " hr.applicant "
2010-05-19 18:32:32 +00:00
_description = " Applicant "
2010-02-28 20:36:51 +00:00
_order = " id desc "
2012-08-22 15:31:45 +00:00
_inherit = [ ' mail.thread ' , ' ir.needaction_mixin ' ]
2010-08-02 09:57:42 +00:00
2012-05-25 11:51:43 +00:00
def _get_default_department_id ( self , cr , uid , context = None ) :
""" Gives default department by checking if present in the context """
2012-05-30 11:18:31 +00:00
return ( self . _resolve_department_id_from_context ( cr , uid , context = context ) or False )
2012-05-25 11:51:43 +00:00
def _get_default_stage_id ( self , cr , uid , context = None ) :
""" Gives default stage_id """
department_id = self . _get_default_department_id ( cr , uid , context = context )
return self . stage_find ( cr , uid , [ ] , department_id , [ ( ' state ' , ' = ' , ' draft ' ) ] , context = context )
def _resolve_department_id_from_context ( self , cr , uid , context = None ) :
""" Returns ID of department based on the value of ' default_department_id '
context key , or None if it cannot be resolved to a single
department .
"""
if context is None :
context = { }
if type ( context . get ( ' default_department_id ' ) ) in ( int , long ) :
return context . get ( ' default_department_id ' )
if isinstance ( context . get ( ' default_department_id ' ) , basestring ) :
department_name = context [ ' default_department_id ' ]
department_ids = self . pool . get ( ' hr.department ' ) . name_search ( cr , uid , name = department_name , context = context )
if len ( department_ids ) == 1 :
return int ( department_ids [ 0 ] [ 0 ] )
return None
def _read_group_stage_ids ( self , cr , uid , ids , domain , read_group_order = None , access_rights_uid = None , context = None ) :
access_rights_uid = access_rights_uid or uid
stage_obj = self . pool . get ( ' hr.recruitment.stage ' )
order = stage_obj . _order
# lame hack to allow reverting search, should just work in the trivial case
if read_group_order == ' stage_id desc ' :
order = " %s desc " % order
2012-05-31 13:16:26 +00:00
# retrieve section_id from the context and write the domain
# - ('id', 'in', 'ids'): add columns that should be present
# - OR ('department_id', '=', False), ('fold', '=', False): add default columns that are not folded
# - OR ('department_id', 'in', department_id), ('fold', '=', False) if department_id: add department columns that are not folded
2012-05-25 11:51:43 +00:00
department_id = self . _resolve_department_id_from_context ( cr , uid , context = context )
search_domain = [ ]
if department_id :
2012-09-06 16:18:12 +00:00
search_domain + = [ ' | ' , ( ' department_id ' , ' = ' , department_id ) ]
search_domain + = [ ' | ' , ( ' id ' , ' in ' , ids ) , ( ' department_id ' , ' = ' , False ) ]
2012-05-25 11:51:43 +00:00
stage_ids = stage_obj . _search ( cr , uid , search_domain , order = order , access_rights_uid = access_rights_uid , context = context )
result = stage_obj . name_get ( cr , access_rights_uid , stage_ids , context = context )
# restore order of the search
result . sort ( lambda x , y : cmp ( stage_ids . index ( x [ 0 ] ) , stage_ids . index ( y [ 0 ] ) ) )
2012-09-06 15:23:03 +00:00
fold = { }
for stage in stage_obj . browse ( cr , access_rights_uid , stage_ids , context = context ) :
fold [ stage . id ] = stage . fold or False
return result , fold
2010-08-02 09:57:42 +00:00
def _compute_day ( self , cr , uid , ids , fields , args , context = None ) :
"""
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param ids : List of Openday ’ s IDs
@return : difference between current date and log date
@param context : A standard dictionary for contextual values
"""
res = { }
for issue in self . browse ( cr , uid , ids , context = context ) :
for field in fields :
res [ issue . id ] = { }
duration = 0
ans = False
hours = 0
if field in [ ' day_open ' ] :
if issue . date_open :
date_create = datetime . strptime ( issue . create_date , " % Y- % m- %d % H: % M: % S " )
date_open = datetime . strptime ( issue . date_open , " % Y- % m- %d % H: % M: % S " )
ans = date_open - date_create
elif field in [ ' day_close ' ] :
if issue . date_closed :
date_create = datetime . strptime ( issue . create_date , " % Y- % m- %d % H: % M: % S " )
date_close = datetime . strptime ( issue . date_closed , " % Y- % m- %d % H: % M: % S " )
ans = date_close - date_create
if ans :
duration = float ( ans . days )
res [ issue . id ] [ field ] = abs ( float ( duration ) )
return res
2010-02-28 20:36:51 +00:00
_columns = {
2012-06-25 07:17:05 +00:00
' name ' : fields . char ( ' Subject ' , size = 128 , required = True ) ,
2010-06-10 04:38:03 +00:00
' active ' : fields . boolean ( ' Active ' , help = " If the active field is set to false, it will allow you to hide the case without removing it. " ) ,
' description ' : fields . text ( ' Description ' ) ,
2010-05-14 09:29:24 +00:00
' email_from ' : fields . char ( ' Email ' , size = 128 , help = " These people will receive email. " ) ,
2010-10-27 12:49:59 +00:00
' email_cc ' : fields . text ( ' Watchers Emails ' , size = 252 , help = " These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma " ) ,
2010-05-14 09:29:24 +00:00
' probability ' : fields . float ( ' Probability ' ) ,
2012-06-13 14:36:42 +00:00
' partner_id ' : fields . many2one ( ' res.partner ' , ' Contact ' ) ,
2011-01-17 11:20:56 +00:00
' create_date ' : fields . datetime ( ' Creation Date ' , readonly = True , select = True ) ,
2010-10-27 12:49:59 +00:00
' write_date ' : fields . datetime ( ' Update Date ' , readonly = True ) ,
2012-05-25 11:51:43 +00:00
' stage_id ' : fields . many2one ( ' hr.recruitment.stage ' , ' Stage ' ,
2012-09-05 05:56:27 +00:00
domain = " [ ' & ' , ( ' fold ' , ' = ' , False), ' | ' , ( ' department_id ' , ' = ' , department_id), ( ' department_id ' , ' = ' , False)] " ) ,
2012-05-22 14:39:36 +00:00
' state ' : fields . related ( ' stage_id ' , ' state ' , type = " selection " , store = True ,
2012-10-12 11:42:58 +00:00
selection = AVAILABLE_STATES , string = " Status " , readonly = True ,
help = ' The status is set to \' Draft \' , when a case is created. \
If the case is in progress the status is set to \' Open \' . \
When the case is over , the status is set to \' Done \' . \
If the case needs to be reviewed then the status is \
2012-05-22 14:39:36 +00:00
set to \' Pending \' . ' ) ,
2012-09-03 05:05:25 +00:00
' categ_ids ' : fields . many2many ( ' hr.applicant_category ' , string = ' Tags ' ) ,
2010-05-14 09:29:24 +00:00
' company_id ' : fields . many2one ( ' res.company ' , ' Company ' ) ,
' user_id ' : fields . many2one ( ' res.users ' , ' Responsible ' ) ,
2010-05-12 08:36:32 +00:00
# Applicant Columns
2011-01-17 11:20:56 +00:00
' date_closed ' : fields . datetime ( ' Closed ' , readonly = True , select = True ) ,
' date_open ' : fields . datetime ( ' Opened ' , readonly = True , select = True ) ,
2010-02-28 20:36:51 +00:00
' date ' : fields . datetime ( ' Date ' ) ,
2010-07-26 06:15:27 +00:00
' date_action ' : fields . date ( ' Next Action Date ' ) ,
' title_action ' : fields . char ( ' Next Action ' , size = 64 ) ,
2010-02-28 20:36:51 +00:00
' priority ' : fields . selection ( AVAILABLE_PRIORITIES , ' Appreciation ' ) ,
' job_id ' : fields . many2one ( ' hr.job ' , ' Applied Job ' ) ,
2011-08-18 19:30:44 +00:00
' salary_proposed_extra ' : fields . char ( ' Proposed Salary Extra ' , size = 100 , help = " Salary Proposed by the Organisation, extra advantages " ) ,
' salary_expected_extra ' : fields . char ( ' Expected Salary Extra ' , size = 100 , help = " Salary Expected by Applicant, extra advantages " ) ,
2010-06-10 04:38:03 +00:00
' salary_proposed ' : fields . float ( ' Proposed Salary ' , help = " Salary Proposed by the Organisation " ) ,
' salary_expected ' : fields . float ( ' Expected Salary ' , help = " Salary Expected by Applicant " ) ,
2012-07-05 15:49:41 +00:00
' availability ' : fields . integer ( ' Availability ' ) ,
2010-02-28 20:36:51 +00:00
' partner_name ' : fields . char ( " Applicant ' s Name " , size = 64 ) ,
' partner_phone ' : fields . char ( ' Phone ' , size = 32 ) ,
' partner_mobile ' : fields . char ( ' Mobile ' , size = 32 ) ,
2010-07-26 06:15:27 +00:00
' type_id ' : fields . many2one ( ' hr.recruitment.degree ' , ' Degree ' ) ,
2010-10-27 12:49:59 +00:00
' department_id ' : fields . many2one ( ' hr.department ' , ' Department ' ) ,
' survey ' : fields . related ( ' job_id ' , ' survey_id ' , type = ' many2one ' , relation = ' survey ' , string = ' Survey ' ) ,
' response ' : fields . integer ( " Response " ) ,
2012-05-17 09:34:46 +00:00
' reference ' : fields . char ( ' Referred By ' , size = 128 ) ,
2011-08-18 19:30:44 +00:00
' source_id ' : fields . many2one ( ' hr.recruitment.source ' , ' Source ' ) ,
2010-08-02 09:57:42 +00:00
' day_open ' : fields . function ( _compute_day , string = ' Days to Open ' , \
2011-07-05 12:28:57 +00:00
multi = ' day_open ' , type = " float " , store = True ) ,
2010-08-02 09:57:42 +00:00
' day_close ' : fields . function ( _compute_day , string = ' Days to Close ' , \
2011-07-05 12:28:57 +00:00
multi = ' day_close ' , type = " float " , store = True ) ,
2011-09-16 12:03:52 +00:00
' color ' : fields . integer ( ' Color Index ' ) ,
2012-02-28 05:21:14 +00:00
' emp_id ' : fields . many2one ( ' hr.employee ' , ' employee ' ) ,
2012-08-10 14:43:39 +00:00
' user_email ' : fields . related ( ' user_id ' , ' email ' , type = ' char ' , string = ' User Email ' , readonly = True ) ,
2010-02-28 20:36:51 +00:00
}
2010-06-10 04:38:03 +00:00
2010-05-20 06:16:37 +00:00
_defaults = {
2010-06-10 04:38:03 +00:00
' active ' : lambda * a : 1 ,
2012-05-25 11:51:43 +00:00
' user_id ' : lambda s , cr , uid , c : uid ,
' email_from ' : lambda s , cr , uid , c : s . _get_default_email ( cr , uid , c ) ,
' stage_id ' : lambda s , cr , uid , c : s . _get_default_stage_id ( cr , uid , c ) ,
' department_id ' : lambda s , cr , uid , c : s . _get_default_department_id ( cr , uid , c ) ,
2011-08-18 19:30:44 +00:00
' priority ' : lambda * a : ' ' ,
2012-07-05 12:22:07 +00:00
' company_id ' : lambda s , cr , uid , c : s . pool . get ( ' res.company ' ) . _company_default_get ( cr , uid , ' hr.applicant ' , context = c ) ,
2011-09-16 12:03:52 +00:00
' color ' : 0 ,
2010-05-20 06:16:37 +00:00
}
2010-04-07 14:40:28 +00:00
2011-11-13 12:45:31 +00:00
_group_by_full = {
' stage_id ' : _read_group_stage_ids
}
2012-03-05 18:40:03 +00:00
def onchange_job ( self , cr , uid , ids , job , context = None ) :
2010-05-10 12:59:15 +00:00
result = { }
2010-07-27 07:11:45 +00:00
2010-05-10 12:59:15 +00:00
if job :
2010-10-08 13:22:47 +00:00
job_obj = self . pool . get ( ' hr.job ' )
2010-07-27 07:11:45 +00:00
result [ ' department_id ' ] = job_obj . browse ( cr , uid , job , context = context ) . department_id . id
2010-05-10 12:59:15 +00:00
return { ' value ' : result }
2010-10-08 13:22:47 +00:00
return { ' value ' : { ' department_id ' : False } }
2010-05-10 12:59:15 +00:00
2011-03-04 07:25:51 +00:00
def onchange_department_id ( self , cr , uid , ids , department_id = False , context = None ) :
obj_recru_stage = self . pool . get ( ' hr.recruitment.stage ' )
stage_ids = obj_recru_stage . search ( cr , uid , [ ' | ' , ( ' department_id ' , ' = ' , department_id ) , ( ' department_id ' , ' = ' , False ) ] , context = context )
stage_id = stage_ids and stage_ids [ 0 ] or False
return { ' value ' : { ' stage_id ' : stage_id } }
2011-03-04 06:44:06 +00:00
2012-05-25 11:51:43 +00:00
def stage_find ( self , cr , uid , cases , section_id , domain = [ ] , order = ' sequence ' , context = None ) :
""" Override of the base.stage method
Parameter of the stage search taken from the lead :
- department_id : if set , stages must belong to this section or
be a default case
2010-04-07 14:40:28 +00:00
"""
2012-05-25 11:51:43 +00:00
if isinstance ( cases , ( int , long ) ) :
cases = self . browse ( cr , uid , cases , context = context )
2012-05-31 14:19:30 +00:00
# collect all section_ids
department_ids = [ ]
2012-05-25 11:51:43 +00:00
if section_id :
2012-05-31 14:19:30 +00:00
department_ids . append ( section_id )
2012-05-25 11:51:43 +00:00
for case in cases :
2012-05-31 14:19:30 +00:00
if case . department_id :
department_ids . append ( case . department_id . id )
# OR all section_ids and OR with case_default
search_domain = [ ]
if department_ids :
search_domain + = [ ' | ' , ( ' department_id ' , ' in ' , department_ids ) ]
search_domain . append ( ( ' department_id ' , ' = ' , False ) )
# AND with the domain in parameter
search_domain + = list ( domain )
# perform search, return the first found
stage_ids = self . pool . get ( ' hr.recruitment.stage ' ) . search ( cr , uid , search_domain , order = order , context = context )
2012-05-22 14:48:06 +00:00
if stage_ids :
return stage_ids [ 0 ]
return False
2010-04-07 14:40:28 +00:00
def action_makeMeeting ( self , cr , uid , ids , context = None ) :
2012-07-06 12:29:59 +00:00
""" This opens Meeting ' s calendar view to schedule meeting on current applicant
@return : Dictionary value for created Meeting view
2010-04-07 14:40:28 +00:00
"""
2012-07-06 12:29:59 +00:00
applicant = self . browse ( cr , uid , ids [ 0 ] , context )
category = self . pool . get ( ' ir.model.data ' ) . get_object ( cr , uid , ' hr_recruitment ' , ' categ_meet_interview ' , context )
res = self . pool . get ( ' ir.actions.act_window ' ) . for_xml_id ( cr , uid , ' base_calendar ' , ' action_crm_meeting ' , context )
res [ ' context ' ] = {
2012-07-14 16:22:03 +00:00
' default_partner_ids ' : applicant . partner_id and [ applicant . partner_id . id ] or False ,
2012-07-06 12:29:59 +00:00
' default_user_id ' : uid ,
' default_name ' : applicant . name ,
2012-07-14 16:22:03 +00:00
' default_categ_ids ' : category and [ category . id ] or False ,
2012-07-06 12:29:59 +00:00
}
return res
2010-04-07 14:40:28 +00:00
2010-04-07 13:46:01 +00:00
def action_print_survey ( self , cr , uid , ids , context = None ) :
"""
If response is available then print this response otherwise print survey form ( print template of the survey ) .
@param self : The object pointer
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param ids : List of Survey IDs
@param context : A standard dictionary for contextual values
2010-10-27 12:49:59 +00:00
@return : Dictionary value for print survey form .
2010-04-07 13:46:01 +00:00
"""
2010-11-23 07:05:05 +00:00
if context is None :
2010-04-07 13:46:01 +00:00
context = { }
2010-07-27 07:11:45 +00:00
record = self . browse ( cr , uid , ids , context = context )
2010-04-08 05:25:40 +00:00
record = record and record [ 0 ]
2010-10-27 12:49:59 +00:00
context . update ( { ' survey_id ' : record . survey . id , ' response_id ' : [ record . response ] , ' response_no ' : 0 , } )
2010-11-19 13:48:01 +00:00
value = self . pool . get ( " survey " ) . action_print_survey ( cr , uid , ids , context = context )
2010-04-09 11:22:38 +00:00
return value
2010-06-24 19:53:32 +00:00
2011-08-22 17:16:59 +00:00
def message_new ( self , cr , uid , msg , custom_values = None , context = None ) :
2012-06-04 14:12:54 +00:00
""" Overrides mail_thread message_new that is called by the mailgateway
through message_process .
This override updates the document according to the email .
"""
if custom_values is None : custom_values = { }
2012-10-09 15:54:20 +00:00
desc = html2plaintext ( msg . get ( ' body ' ) ) if msg . get ( ' body ' ) else ' '
2012-06-04 14:12:54 +00:00
custom_values . update ( {
' name ' : msg . get ( ' subject ' ) or _ ( " No Subject " ) ,
2012-10-09 15:54:20 +00:00
' description ' : desc ,
2012-06-04 14:12:54 +00:00
' email_from ' : msg . get ( ' from ' ) ,
2010-06-24 19:53:32 +00:00
' email_cc ' : msg . get ( ' cc ' ) ,
' user_id ' : False ,
2012-06-04 14:12:54 +00:00
} )
if msg . get ( ' priority ' ) :
custom_values [ ' priority ' ] = msg . get ( ' priority ' )
return super ( hr_applicant , self ) . message_new ( cr , uid , msg , custom_values = custom_values , context = context )
def message_update ( self , cr , uid , ids , msg , update_vals = None , context = None ) :
""" Override mail_thread message_update that is called by the mailgateway
through message_process .
This method updates the document according to the email .
"""
2010-06-24 19:53:32 +00:00
if isinstance ( ids , ( str , int , long ) ) :
ids = [ ids ]
2012-06-04 14:12:54 +00:00
if update_vals is None : vals = { }
2012-08-16 14:44:03 +00:00
2012-06-04 14:12:54 +00:00
update_vals . update ( {
' description ' : msg . get ( ' body ' ) ,
' email_from ' : msg . get ( ' from ' ) ,
' email_cc ' : msg . get ( ' cc ' ) ,
2010-06-24 19:53:32 +00:00
} )
2012-06-04 14:12:54 +00:00
if msg . get ( ' priority ' ) :
update_vals [ ' priority ' ] = msg . get ( ' priority ' )
2010-06-24 19:53:32 +00:00
maps = {
2012-06-04 14:12:54 +00:00
' cost ' : ' planned_cost ' ,
2010-06-24 19:53:32 +00:00
' revenue ' : ' planned_revenue ' ,
2012-06-04 14:12:54 +00:00
' probability ' : ' probability ' ,
2010-06-24 19:53:32 +00:00
}
2012-08-17 12:06:06 +00:00
for line in msg . get ( ' body ' , ' ' ) . split ( ' \n ' ) :
2010-06-24 19:53:32 +00:00
line = line . strip ( )
res = tools . misc . command_re . match ( line )
if res and maps . get ( res . group ( 1 ) . lower ( ) , False ) :
key = maps . get ( res . group ( 1 ) . lower ( ) )
2012-06-04 14:12:54 +00:00
update_vals [ key ] = res . group ( 2 ) . lower ( )
2010-07-26 06:15:27 +00:00
2012-06-04 14:12:54 +00:00
return super ( hr_applicant , self ) . message_update ( cr , uids , ids , update_vals = update_vals , context = context )
2010-06-24 19:53:32 +00:00
2012-02-28 05:21:14 +00:00
def create ( self , cr , uid , vals , context = None ) :
obj_id = super ( hr_applicant , self ) . create ( cr , uid , vals , context = context )
2012-03-19 09:37:39 +00:00
self . create_send_note ( cr , uid , [ obj_id ] , context = context )
2012-02-28 05:21:14 +00:00
return obj_id
2012-02-24 08:01:01 +00:00
def case_open ( self , cr , uid , ids , context = None ) :
2010-07-08 10:14:24 +00:00
"""
2012-02-24 08:01:01 +00:00
open Request of the applicant for the hr_recruitment
2010-07-08 10:14:24 +00:00
"""
2012-02-24 08:01:01 +00:00
res = super ( hr_applicant , self ) . case_open ( cr , uid , ids , context )
2010-08-02 09:57:42 +00:00
date = self . read ( cr , uid , ids , [ ' date_open ' ] ) [ 0 ]
if not date [ ' date_open ' ] :
self . write ( cr , uid , ids , { ' date_open ' : time . strftime ( ' % Y- % m- %d % H: % M: % S ' ) , } )
2010-07-08 10:14:24 +00:00
return res
2012-02-28 05:21:14 +00:00
def case_close ( self , cr , uid , ids , context = None ) :
res = super ( hr_applicant , self ) . case_close ( cr , uid , ids , context )
2010-07-08 10:14:24 +00:00
return res
2010-06-24 19:53:32 +00:00
2012-02-28 05:21:14 +00:00
def case_close_with_emp ( self , cr , uid , ids , context = None ) :
2012-03-20 16:50:27 +00:00
if context is None :
context = { }
2011-11-28 06:33:18 +00:00
hr_employee = self . pool . get ( ' hr.employee ' )
2011-11-30 07:02:26 +00:00
model_data = self . pool . get ( ' ir.model.data ' )
act_window = self . pool . get ( ' ir.actions.act_window ' )
emp_id = False
2012-03-20 16:50:27 +00:00
for applicant in self . browse ( cr , uid , ids , context = context ) :
2011-11-28 06:33:18 +00:00
address_id = False
if applicant . partner_id :
2012-09-16 15:18:26 +00:00
address_id = self . pool . get ( ' res.partner ' ) . address_get ( cr , uid , [ applicant . partner_id . id ] , [ ' contact ' ] ) [ ' contact ' ]
2011-11-28 06:33:18 +00:00
if applicant . job_id :
applicant . job_id . write ( { ' no_of_recruitment ' : applicant . job_id . no_of_recruitment - 1 } )
emp_id = hr_employee . create ( cr , uid , { ' name ' : applicant . partner_name or applicant . name ,
' job_id ' : applicant . job_id . id ,
' address_home_id ' : address_id ,
' department_id ' : applicant . department_id . id
} )
2012-03-20 16:50:27 +00:00
self . write ( cr , uid , [ applicant . id ] , { ' emp_id ' : emp_id } , context = context )
2012-02-28 05:21:14 +00:00
self . case_close ( cr , uid , [ applicant . id ] , context )
2011-11-28 06:33:18 +00:00
else :
2011-12-31 07:57:20 +00:00
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( ' You must define Applied Job for this applicant. ' ) )
2011-11-30 07:02:26 +00:00
action_model , action_id = model_data . get_object_reference ( cr , uid , ' hr ' , ' open_view_employee_list ' )
dict_act_window = act_window . read ( cr , uid , action_id , [ ] )
if emp_id :
dict_act_window [ ' res_id ' ] = emp_id
dict_act_window [ ' view_mode ' ] = ' form,tree '
return dict_act_window
2011-02-16 12:04:50 +00:00
2012-02-28 05:21:14 +00:00
def case_cancel ( self , cr , uid , ids , context = None ) :
""" Overrides cancel for crm_case for setting probability
2010-08-02 09:57:42 +00:00
"""
2012-02-28 05:21:14 +00:00
res = super ( hr_applicant , self ) . case_cancel ( cr , uid , ids , context )
self . write ( cr , uid , ids , { ' probability ' : 0.0 } )
return res
def case_pending ( self , cr , uid , ids , context = None ) :
""" Marks case as pending """
res = super ( hr_applicant , self ) . case_pending ( cr , uid , ids , context )
self . write ( cr , uid , ids , { ' probability ' : 0.0 } )
return res
2010-10-14 10:43:56 +00:00
2012-02-28 05:21:14 +00:00
def case_reset ( self , cr , uid , ids , context = None ) :
""" Resets case as draft
"""
res = super ( hr_applicant , self ) . case_reset ( cr , uid , ids , context )
2010-10-27 12:49:59 +00:00
self . write ( cr , uid , ids , { ' date_open ' : False , ' date_closed ' : False } )
2010-08-02 09:57:42 +00:00
return res
2011-12-06 17:37:55 +00:00
def set_priority ( self , cr , uid , ids , priority , * args ) :
""" Set applicant priority
2011-09-16 12:03:52 +00:00
"""
return self . write ( cr , uid , ids , { ' priority ' : priority } )
def set_high_priority ( self , cr , uid , ids , * args ) :
2011-12-06 17:37:55 +00:00
""" Set applicant priority to high
2011-09-16 12:03:52 +00:00
"""
return self . set_priority ( cr , uid , ids , ' 1 ' )
def set_normal_priority ( self , cr , uid , ids , * args ) :
2011-12-06 17:37:55 +00:00
""" Set applicant priority to normal
2011-09-16 12:03:52 +00:00
"""
return self . set_priority ( cr , uid , ids , ' 3 ' )
2010-08-02 09:57:42 +00:00
2012-04-03 09:02:46 +00:00
# -------------------------------------------------------
# OpenChatter methods and notifications
# -------------------------------------------------------
2012-06-01 09:36:04 +00:00
def stage_set_send_note ( self , cr , uid , ids , stage_id , context = None ) :
""" Override of the (void) default notification method. """
if not stage_id : return True
stage_name = self . pool . get ( ' hr.recruitment.stage ' ) . name_get ( cr , uid , [ stage_id ] , context = context ) [ 0 ] [ 1 ]
2012-09-19 13:12:40 +00:00
return self . message_post ( cr , uid , ids , body = _ ( " Stage changed to <b> %s </b>. " ) % ( stage_name ) , context = context )
2012-06-01 09:36:04 +00:00
2012-04-03 09:02:46 +00:00
def case_get_note_msg_prefix ( self , cr , uid , id , context = None ) :
return ' Applicant '
def case_open_send_note ( self , cr , uid , ids , context = None ) :
message = _ ( " Applicant has been set <b>in progress</b>. " )
2012-08-17 10:03:02 +00:00
return self . message_post ( cr , uid , ids , body = message , context = context )
2012-04-03 09:02:46 +00:00
def case_close_send_note ( self , cr , uid , ids , context = None ) :
if context is None :
context = { }
for applicant in self . browse ( cr , uid , ids , context = context ) :
2012-10-02 20:40:23 +00:00
if applicant . job_id :
self . pool . get ( ' hr.job ' ) . message_post ( cr , uid , [ applicant . job_id . id ] , body = _ ( ' New employee joined the company %s . ' ) % ( applicant . name , ) , subtype = " hr_recruitment.mt_hired " , context = context )
2012-04-03 09:02:46 +00:00
if applicant . emp_id :
message = _ ( " Applicant has been <b>hired</b> and created as an employee. " )
2012-08-17 10:03:02 +00:00
self . message_post ( cr , uid , [ applicant . id ] , body = message , context = context )
2012-04-03 09:02:46 +00:00
else :
message = _ ( " Applicant has been <b>hired</b>. " )
2012-08-17 10:03:02 +00:00
self . message_post ( cr , uid , [ applicant . id ] , body = message , context = context )
2012-04-03 09:02:46 +00:00
return True
def case_cancel_send_note ( self , cr , uid , ids , context = None ) :
msg = ' Applicant <b>refused</b>. '
2012-08-17 10:03:02 +00:00
return self . message_post ( cr , uid , ids , body = msg , context = context )
2010-08-02 09:57:42 +00:00
2012-04-03 09:02:46 +00:00
def case_reset_send_note ( self , cr , uid , ids , context = None ) :
message = _ ( " Applicant has been set as <b>new</b>. " )
2012-08-17 10:03:02 +00:00
return self . message_post ( cr , uid , ids , body = message , context = context )
2012-04-03 09:02:46 +00:00
def create_send_note ( self , cr , uid , ids , context = None ) :
message = _ ( " Applicant has been <b>created</b>. " )
2012-10-02 20:40:23 +00:00
for applicant in self . browse ( cr , uid , ids , context = context ) :
if applicant . job_id :
self . pool . get ( ' hr.job ' ) . message_post ( cr , uid , [ applicant . job_id . id ] , body = message , subtype = " hr_recruitment.mt_applicant_new " , context = context )
2012-08-17 10:03:02 +00:00
return self . message_post ( cr , uid , ids , body = message , context = context )
2010-03-02 12:48:29 +00:00
class hr_job ( osv . osv ) :
_inherit = " hr.job "
_name = " hr.job "
2012-06-25 11:31:33 +00:00
_inherits = { ' mail.alias ' : ' alias_id ' }
2010-03-02 12:48:29 +00:00
_columns = {
2011-11-08 10:21:53 +00:00
' survey_id ' : fields . many2one ( ' survey ' , ' Interview Form ' , help = " Choose an interview form for this job position and you will be able to print/answer this interview from all applicants who apply for this job " ) ,
2012-08-16 14:44:03 +00:00
' alias_id ' : fields . many2one ( ' mail.alias ' , ' Alias ' , ondelete = " cascade " , required = True ,
2012-08-06 01:27:17 +00:00
help = " Email alias for this job position. New emails will automatically "
" create new applicants for this job position. " ) ,
2010-03-02 12:48:29 +00:00
}
2012-08-14 10:51:14 +00:00
_defaults = {
' alias_domain ' : False , # always hide alias during creation
}
def _auto_init ( self , cr , context = None ) :
""" Installation hook to create aliases for all jobs and avoid constraint errors. """
2012-08-23 15:32:03 +00:00
self . pool . get ( ' mail.alias ' ) . migrate_to_alias ( cr , self . _name , self . _table , super ( hr_job , self ) . _auto_init ,
self . _columns [ ' alias_id ' ] , ' name ' , alias_prefix = ' job+ ' , alias_defaults = { ' job_id ' : ' id ' } , context = context )
2012-08-07 14:27:36 +00:00
2012-06-25 11:31:33 +00:00
def create ( self , cr , uid , vals , context = None ) :
2012-08-07 14:27:36 +00:00
mail_alias = self . pool . get ( ' mail.alias ' )
2012-07-04 08:37:54 +00:00
if not vals . get ( ' alias_id ' ) :
2012-08-07 14:27:36 +00:00
vals . pop ( ' alias_name ' , None ) # prevent errors during copy()
2012-08-16 14:44:03 +00:00
alias_id = mail_alias . create_unique_alias ( cr , uid ,
2012-08-07 14:27:36 +00:00
# Using '+' allows using subaddressing for those who don't
# have a catchall domain setup.
2012-08-09 17:17:26 +00:00
{ ' alias_name ' : ' jobs+ ' + vals [ ' name ' ] } ,
2012-08-06 00:44:17 +00:00
model_name = " hr.applicant " ,
context = context )
vals [ ' alias_id ' ] = alias_id
2012-08-07 14:27:36 +00:00
res = super ( hr_job , self ) . create ( cr , uid , vals , context )
mail_alias . write ( cr , uid , [ vals [ ' alias_id ' ] ] , { " alias_defaults " : { ' job_id ' : res } } , context )
2012-06-25 11:31:33 +00:00
return res
2012-07-05 12:54:17 +00:00
def unlink ( self , cr , uid , ids , context = None ) :
2012-07-05 14:17:06 +00:00
# Cascade-delete mail aliases as well, as they should not exist without the job position.
mail_alias = self . pool . get ( ' mail.alias ' )
alias_ids = [ job . alias_id . id for job in self . browse ( cr , uid , ids , context = context ) if job . alias_id ]
2012-07-05 12:54:17 +00:00
res = super ( hr_job , self ) . unlink ( cr , uid , ids , context = context )
2012-07-05 14:17:06 +00:00
mail_alias . unlink ( cr , uid , alias_ids , context = context )
2012-07-05 12:54:17 +00:00
return res
2012-08-16 14:44:03 +00:00
2012-05-17 09:58:16 +00:00
def action_print_survey ( self , cr , uid , ids , context = None ) :
if context is None :
context = { }
2012-05-22 09:55:32 +00:00
datas = { }
record = self . browse ( cr , uid , ids , context = context ) [ 0 ]
if record . survey_id :
datas [ ' ids ' ] = [ record . survey_id . id ]
datas [ ' model ' ] = ' survey.print '
context . update ( { ' response_id ' : [ 0 ] , ' response_no ' : 0 , } )
return {
2012-10-02 10:29:15 +00:00
' type ' : ' ir.actions.report.xml ' ,
' report_name ' : ' survey.form ' ,
' datas ' : datas ,
' context ' : context ,
' nodestroy ' : True ,
}
2012-06-14 14:41:59 +00:00
2012-08-16 14:44:03 +00:00
class applicant_category ( osv . osv ) :
""" Category of applicant """
_name = " hr.applicant_category "
_description = " Category of applicant "
_columns = {
' name ' : fields . char ( ' Name ' , size = 64 , required = True , translate = True ) ,
2010-03-02 12:48:29 +00:00
}
2010-05-11 13:54:14 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: