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
from datetime import datetime , timedelta
2010-05-12 08:36:32 +00:00
from osv import fields , osv
from crm import crm
2010-06-24 19:53:32 +00:00
import tools
import collections
import binascii
import tools
from tools . translate import _
2011-02-24 10:13:05 +00:00
from crm import wizard
2011-09-07 18:33:28 +00:00
wizard . mail_compose_message . SUPPORTED_MODELS . append ( ' hr.applicant ' )
2010-02-28 20:36:51 +00:00
AVAILABLE_STATES = [
2010-05-14 09:29:24 +00:00
( ' draft ' , ' New ' ) ,
( ' open ' , ' In Progress ' ) ,
2010-02-28 20:36:51 +00:00
( ' cancel ' , ' Refused ' ) ,
( ' done ' , ' Hired ' ) ,
2010-05-12 08:36:32 +00:00
( ' pending ' , ' Pending ' )
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 ) ,
}
hr_recruitment_source ( )
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. " ) ,
2011-11-13 12:45:31 +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 tempy this field. " ) ,
2010-05-11 13:54:14 +00:00
' requirements ' : fields . text ( ' Requirements ' )
}
_defaults = {
' sequence ' : 1 ,
}
hr_recruitment_stage ( )
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
hr_recruitment_degree ( )
2010-08-17 12:54:00 +00:00
class hr_applicant ( crm . crm_case , osv . osv ) :
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 "
2011-08-22 17:16:59 +00:00
_inherit = [ ' mail.thread ' ]
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
date_until = issue . date_open
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 " )
date_until = issue . date_closed
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 = {
2010-06-10 04:38:03 +00:00
' name ' : fields . char ( ' Name ' , size = 128 , required = True ) ,
2011-08-22 17:16:59 +00:00
' message_ids ' : fields . one2many ( ' mail.message ' , ' res_id ' , ' Messages ' , domain = [ ( ' model ' , ' = ' , _name ) ] ) ,
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 ' ) ,
' partner_id ' : fields . many2one ( ' res.partner ' , ' Partner ' ) ,
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 ) ,
2010-07-20 07:17:40 +00:00
' stage_id ' : fields . many2one ( ' hr.recruitment.stage ' , ' Stage ' ) ,
2010-05-14 09:29:24 +00:00
' state ' : fields . selection ( AVAILABLE_STATES , ' State ' , size = 16 , readonly = True ,
2010-05-12 08:36:32 +00:00
help = ' The state is set to \' Draft \' , when a case is created. \
\nIf the case is in progress the state is set to \' Open \' . \
\nWhen the case is over , the state is set to \' Done \' . \
2010-05-14 09:29:24 +00:00
\nIf the case needs to be reviewed then the state is set to \' Pending \' . ' ) ,
' 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 " ) ,
2010-02-28 20:36:51 +00:00
' availability ' : fields . integer ( ' Availability (Days) ' ) ,
' 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 ' ) ,
2010-02-28 20:36:51 +00:00
' state ' : fields . selection ( AVAILABLE_STATES , ' State ' , size = 16 , readonly = True ) ,
2010-10-27 12:49:59 +00:00
' survey ' : fields . related ( ' job_id ' , ' survey_id ' , type = ' many2one ' , relation = ' survey ' , string = ' Survey ' ) ,
' response ' : fields . integer ( " Response " ) ,
2011-08-18 19:30:44 +00:00
' reference ' : fields . char ( ' Refered By ' , size = 128 ) ,
' 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 ' ) ,
2011-12-05 15:07:06 +00:00
' user_email ' : fields . related ( ' user_id ' , ' user_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 ,
' user_id ' : lambda self , cr , uid , context : uid ,
' email_from ' : crm . crm_case . _get_default_email ,
2010-05-20 06:16:37 +00:00
' state ' : lambda * a : ' draft ' ,
2011-08-18 19:30:44 +00:00
' priority ' : lambda * a : ' ' ,
2010-06-10 04:38:03 +00:00
' company_id ' : lambda s , cr , uid , c : s . pool . get ( ' res.company ' ) . _company_default_get ( cr , uid , ' crm.helpdesk ' , 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-23 13:31:32 +00:00
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
2011-11-13 12:45:31 +00:00
stage_obj = self . pool . get ( ' hr.recruitment.stage ' )
2011-11-21 16:49:40 +00:00
order = stage_obj . _order
if read_group_order == ' stage_id desc ' :
# lame hack to allow reverting search, should just work in the trivial case
order = " %s desc " % order
2011-11-23 13:31:32 +00:00
stage_ids = stage_obj . _search ( cr , uid , [ ' | ' , ( ' id ' , ' in ' , ids ) , ( ' department_id ' , ' = ' , False ) ] , order = order ,
access_rights_uid = access_rights_uid , context = context )
result = stage_obj . name_get ( cr , access_rights_uid , stage_ids , context = context )
2011-11-21 16:49:40 +00:00
# restore order of the search
result . sort ( lambda x , y : cmp ( stage_ids . index ( x [ 0 ] ) , stage_ids . index ( y [ 0 ] ) ) )
return result
2011-11-13 12:45:31 +00:00
_group_by_full = {
' stage_id ' : _read_group_stage_ids
}
2010-07-27 07:11:45 +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 ) :
if not department_id :
return { ' value ' : { ' stage_id ' : False } }
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
2010-04-07 14:40:28 +00:00
def stage_previous ( self , cr , uid , ids , context = None ) :
""" This function computes previous stage for case from its current stage
2010-04-23 07:24:58 +00:00
using available stage for that case type
2010-04-07 14:40:28 +00:00
@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 case IDs
@param context : A standard dictionary for contextual values """
2010-07-27 07:11:45 +00:00
stage_obj = self . pool . get ( ' hr.recruitment.stage ' )
for case in self . browse ( cr , uid , ids , context = context ) :
2010-07-20 07:17:40 +00:00
department = ( case . department_id . id or False )
2010-04-07 14:40:28 +00:00
st = case . stage_id . id or False
2010-07-27 07:11:45 +00:00
stage_ids = stage_obj . search ( cr , uid , [ ' | ' , ( ' department_id ' , ' = ' , department ) , ( ' department_id ' , ' = ' , False ) ] , context = context )
2010-04-07 14:40:28 +00:00
if st and stage_ids . index ( st ) :
2010-07-27 07:11:45 +00:00
self . write ( cr , uid , [ case . id ] , { ' stage_id ' : stage_ids [ stage_ids . index ( st ) - 1 ] } , context = context )
2011-08-18 19:30:44 +00:00
else :
self . write ( cr , uid , [ case . id ] , { ' stage_id ' : False } , context = context )
2010-04-07 14:40:28 +00:00
return True
def stage_next ( self , cr , uid , ids , context = None ) :
""" This function computes next stage for case from its current stage
2010-04-23 07:24:58 +00:00
using available stage for that case type
2010-04-07 14:40:28 +00:00
@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 case IDs
@param context : A standard dictionary for contextual values """
2010-07-27 07:11:45 +00:00
stage_obj = self . pool . get ( ' hr.recruitment.stage ' )
for case in self . browse ( cr , uid , ids , context = context ) :
2010-07-20 07:17:40 +00:00
department = ( case . department_id . id or False )
2010-04-07 14:40:28 +00:00
st = case . stage_id . id or False
2010-07-27 07:11:45 +00:00
stage_ids = stage_obj . search ( cr , uid , [ ' | ' , ( ' department_id ' , ' = ' , department ) , ( ' department_id ' , ' = ' , False ) ] , context = context )
2011-08-18 19:30:44 +00:00
val = False
2010-04-07 14:40:28 +00:00
if st and len ( stage_ids ) != stage_ids . index ( st ) + 1 :
2011-08-18 19:30:44 +00:00
val = stage_ids [ stage_ids . index ( st ) + 1 ]
elif ( not st ) and stage_ids :
val = stage_ids [ 0 ]
else :
val = False
self . write ( cr , uid , [ case . id ] , { ' stage_id ' : val } , context = context )
2010-04-07 14:40:28 +00:00
return True
def action_makeMeeting ( self , cr , uid , ids , context = None ) :
"""
This opens Meeting ' s calendar view to schedule meeting on current Opportunity
@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 Opportunity to Meeting IDs
@param context : A standard dictionary for contextual values
2010-10-27 12:49:59 +00:00
@return : Dictionary value for created Meeting view
2010-04-07 14:40:28 +00:00
"""
2010-07-27 07:11:45 +00:00
data_obj = self . pool . get ( ' ir.model.data ' )
if context is None :
context = { }
2010-04-07 14:40:28 +00:00
value = { }
2010-07-27 07:11:45 +00:00
for opp in self . browse ( cr , uid , ids , context = context ) :
2010-04-07 14:40:28 +00:00
# Get meeting views
result = data_obj . _get_id ( cr , uid , ' crm ' , ' view_crm_case_meetings_filter ' )
2010-07-27 07:11:45 +00:00
res = data_obj . read ( cr , uid , result , [ ' res_id ' ] , context = context )
2010-04-07 14:40:28 +00:00
id1 = data_obj . _get_id ( cr , uid , ' crm ' , ' crm_case_calendar_view_meet ' )
id2 = data_obj . _get_id ( cr , uid , ' crm ' , ' crm_case_form_view_meet ' )
id3 = data_obj . _get_id ( cr , uid , ' crm ' , ' crm_case_tree_view_meet ' )
if id1 :
id1 = data_obj . browse ( cr , uid , id1 , context = context ) . res_id
if id2 :
id2 = data_obj . browse ( cr , uid , id2 , context = context ) . res_id
if id3 :
id3 = data_obj . browse ( cr , uid , id3 , context = context ) . res_id
context = {
' default_partner_id ' : opp . partner_id and opp . partner_id . id or False ,
' default_email_from ' : opp . email_from ,
' default_state ' : ' open ' ,
' default_name ' : opp . name
}
value = {
2010-04-29 10:54:25 +00:00
' name ' : ( ' Meetings ' ) ,
2010-04-07 14:40:28 +00:00
' domain ' : " [( ' user_id ' , ' = ' , %s )] " % ( uid ) ,
' context ' : context ,
' view_type ' : ' form ' ,
' view_mode ' : ' calendar,form,tree ' ,
' res_model ' : ' crm.meeting ' ,
' view_id ' : False ,
' views ' : [ ( id1 , ' calendar ' ) , ( id2 , ' form ' ) , ( id3 , ' tree ' ) ] ,
' type ' : ' ir.actions.act_window ' ,
' search_view_id ' : res [ ' res_id ' ] ,
' nodestroy ' : True
}
return value
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 ) :
""" Automatically called when new email message arrives """
2011-08-25 12:27:57 +00:00
res_id = super ( hr_applicant , self ) . message_new ( cr , uid , msg , custom_values = custom_values , context = context )
2011-07-05 05:46:19 +00:00
subject = msg . get ( ' subject ' ) or _ ( " No Subject " )
2011-08-22 17:16:59 +00:00
body = msg . get ( ' body_text ' )
2010-06-24 19:53:32 +00:00
msg_from = msg . get ( ' from ' )
priority = msg . get ( ' priority ' )
vals = {
' name ' : subject ,
' email_from ' : msg_from ,
' email_cc ' : msg . get ( ' cc ' ) ,
' description ' : body ,
' user_id ' : False ,
}
2011-08-22 17:16:59 +00:00
if priority :
2010-06-24 19:53:32 +00:00
vals [ ' priority ' ] = priority
2011-08-25 12:27:57 +00:00
vals . update ( self . message_partner_by_email ( cr , uid , msg . get ( ' from ' , False ) ) )
self . write ( cr , uid , [ res_id ] , vals , context )
2011-04-20 06:06:05 +00:00
return res_id
2010-07-26 06:15:27 +00:00
2011-12-09 14:28:39 +00:00
def message_update ( self , cr , uid , ids , msg , vals = None , default_act = ' pending ' , context = None ) :
2010-06-24 19:53:32 +00:00
if isinstance ( ids , ( str , int , long ) ) :
ids = [ ids ]
2011-12-09 14:28:39 +00:00
if vals is None :
vals = { }
2010-06-24 19:53:32 +00:00
msg_from = msg [ ' from ' ]
vals . update ( {
2011-08-22 17:16:59 +00:00
' description ' : msg [ ' body_text ' ]
2010-06-24 19:53:32 +00:00
} )
if msg . get ( ' priority ' , False ) :
vals [ ' priority ' ] = msg . get ( ' priority ' )
maps = {
' cost ' : ' planned_cost ' ,
' revenue ' : ' planned_revenue ' ,
' probability ' : ' probability '
}
vls = { }
2011-08-22 17:16:59 +00:00
for line in msg [ ' body_text ' ] . 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 ( ) )
vls [ key ] = res . group ( 2 ) . lower ( )
2010-07-26 06:15:27 +00:00
2010-06-24 19:53:32 +00:00
vals . update ( vls )
2010-07-27 07:11:45 +00:00
res = self . write ( cr , uid , ids , vals , context = context )
2011-08-25 12:27:57 +00:00
self . message_append_dict ( cr , uid , ids , msg , context = context )
2010-06-24 19:53:32 +00:00
return res
2010-07-08 10:14:24 +00:00
def case_open ( self , cr , uid , ids , * args ) :
"""
@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 case ' s Ids
@param * args : Give Tuple Value
"""
res = super ( hr_applicant , self ) . case_open ( cr , uid , ids , * args )
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
for ( id , name ) in self . name_get ( cr , uid , ids ) :
2010-10-17 17:30:00 +00:00
message = _ ( " The job request ' %s ' has been set ' in progress ' . " ) % name
2010-07-08 10:14:24 +00:00
self . log ( cr , uid , id , message )
return res
def case_close ( self , cr , uid , ids , * args ) :
res = super ( hr_applicant , self ) . case_close ( cr , uid , ids , * args )
for ( id , name ) in self . name_get ( cr , uid , ids ) :
2010-10-17 17:30:00 +00:00
message = _ ( " Applicant ' %s ' is being hired. " ) % name
2010-07-08 10:14:24 +00:00
self . log ( cr , uid , id , message )
return res
2010-06-24 19:53:32 +00:00
2011-03-11 10:07:52 +00:00
def case_close_with_emp ( self , cr , uid , ids , * args ) :
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
2011-11-28 06:33:18 +00:00
for applicant in self . browse ( cr , uid , ids ) :
address_id = False
if applicant . partner_id :
address_id = applicant . partner_id . address_get ( [ ' contact ' ] ) [ ' contact ' ]
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
} )
self . case_close ( cr , uid , [ applicant . id ] , * args )
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
2010-08-02 09:57:42 +00:00
def case_reset ( self , cr , uid , ids , * args ) :
""" Resets case as draft
@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 case Ids
@param * args : Tuple Value for additional Params
"""
2010-10-14 10:43:56 +00:00
2010-08-02 09:57:42 +00:00
res = super ( hr_applicant , self ) . case_reset ( cr , uid , ids , * args )
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
2011-09-16 06:56:54 +00:00
def write ( self , cr , uid , ids , vals , context = None ) :
if ' stage_id ' in vals and vals [ ' stage_id ' ] :
2011-09-19 06:45:13 +00:00
stage = self . pool . get ( ' hr.recruitment.stage ' ) . browse ( cr , uid , vals [ ' stage_id ' ] , context = context )
text = _ ( " Changed Stage to: %s " ) % stage . name
2011-09-16 06:56:54 +00:00
self . message_append ( cr , uid , ids , text , body_text = text , context = context )
return super ( hr_applicant , self ) . write ( cr , uid , ids , vals , context = context )
2010-08-02 09:57:42 +00:00
2010-02-28 20:36:51 +00:00
hr_applicant ( )
2010-03-02 12:48:29 +00:00
class hr_job ( osv . osv ) :
_inherit = " hr.job "
_name = " hr.job "
_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 " ) ,
2010-03-02 12:48:29 +00:00
}
2010-05-11 13:54:14 +00:00
hr_job ( )
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: