diff --git a/addons/hr_recruitment/hr_recruitment.py b/addons/hr_recruitment/hr_recruitment.py index 6ccb0a22c94..bd492b5cd83 100644 --- a/addons/hr_recruitment/hr_recruitment.py +++ b/addons/hr_recruitment/hr_recruitment.py @@ -92,6 +92,13 @@ class hr_applicant(base_stage, osv.Model): _description = "Applicant" _order = "id desc" _inherit = ['mail.thread', 'ir.needaction_mixin'] + _track = { + 'stage_id': { + 'hr_recruitment.mt_applicant_hired': lambda self, cr, uid, obj, ctx=None: obj.stage_id and obj.stage_id.state == 'done' and obj.emp_id, + 'hr_recruitment.mt_applicant_refused': lambda self, cr, uid, obj, ctx=None: obj.stage_id and obj.stage_id.state == 'cancel' and not obj.emp_id, + 'hr_recruitment.mt_stage_changed': lambda self, cr, uid, obj, ctx=None: obj.stage_id and obj.stage_id.state not in ['done', 'cancel'], + }, + } def _get_default_department_id(self, cr, uid, context=None): """ Gives default department by checking if present in the context """ @@ -186,7 +193,7 @@ class hr_applicant(base_stage, osv.Model): 'partner_id': fields.many2one('res.partner', 'Contact'), 'create_date': fields.datetime('Creation Date', readonly=True, select=True), 'write_date': fields.datetime('Update Date', readonly=True), - 'stage_id': fields.many2one ('hr.recruitment.stage', 'Stage', tracked=True, + 'stage_id': fields.many2one ('hr.recruitment.stage', 'Stage', track_visibility=1, domain="['&', ('fold', '=', False), '|', ('department_id', '=', department_id), ('department_id', '=', False)]"), 'state': fields.related('stage_id', 'state', type="selection", store=True, selection=AVAILABLE_STATES, string="Status", readonly=True, @@ -197,7 +204,7 @@ class hr_applicant(base_stage, osv.Model): set to \'Pending\'.'), 'categ_ids': fields.many2many('hr.applicant_category', string='Tags'), 'company_id': fields.many2one('res.company', 'Company'), - 'user_id': fields.many2one('res.users', 'Responsible',tracked=True), + 'user_id': fields.many2one('res.users', 'Responsible', track_visibility=1), # Applicant Columns 'date_closed': fields.datetime('Closed', readonly=True, select=True), 'date_open': fields.datetime('Opened', readonly=True, select=True), @@ -383,7 +390,9 @@ class hr_applicant(base_stage, osv.Model): def create(self, cr, uid, vals, context=None): obj_id = super(hr_applicant, self).create(cr, uid, vals, context=context) - self.create_send_note(cr, uid, [obj_id], context=context) + applicant = self.browse(cr, uid, obj_id, context=context) + if applicant.job_id: + self.pool.get('hr.job').message_post(cr, uid, [applicant.job_id.id], body=_('Applicant created'), subtype="hr_recruitment.mt_job_new_applicant", context=context) return obj_id def case_open(self, cr, uid, ids, context=None): @@ -465,45 +474,6 @@ class hr_applicant(base_stage, osv.Model): """ return self.set_priority(cr, uid, ids, '3') - # ------------------------------------------------------- - # OpenChatter methods and notifications - # ------------------------------------------------------- - - 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 in progress.") - return self.message_post(cr, uid, ids, body=message, context=context) - - 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): - 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,), context=context) - if applicant.emp_id: - message = _("Applicant has been hired and created as an employee.") - self.message_post(cr, uid, [applicant.id], body=message, subtype="hr_recruitment.mt_applicant_hired", context=context) - else: - message = _("Applicant has been hired.") - self.message_post(cr, uid, [applicant.id], body=message, subtype="hr_recruitment.mt_applicant_hired", context=context) - return True - - def case_cancel_send_note(self, cr, uid, ids, context=None): - msg = 'Applicant refused.' - return self.message_post(cr, uid, ids, body=msg, subtype="hr_recruitment.mt_applicant_refused",context=context) - - def case_reset_send_note(self, cr, uid, ids, context=None): - message =_("Applicant has been set as new.") - return self.message_post(cr, uid, ids, body=message, context=context) - - def create_send_note(self, cr, uid, ids, context=None): - message = _("Applicant has been created.") - 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) - return self.message_post(cr, uid, ids, body=message, context=context) class hr_job(osv.osv): _inherit = "hr.job" diff --git a/addons/hr_recruitment/hr_recruitment_data.xml b/addons/hr_recruitment/hr_recruitment_data.xml index a9bc7440276..0d46af13b35 100644 --- a/addons/hr_recruitment/hr_recruitment_data.xml +++ b/addons/hr_recruitment/hr_recruitment_data.xml @@ -462,40 +462,26 @@ - + New Applicant hr.job - - Stage Changed - hr.job - - - - Applicant Hired - hr.job - - - - Refused - hr.job - - Stage Changed hr.applicant - + Stage <b>changed</b> Applicant Hired hr.applicant - + Applicant <b>hired</b> Applicant Refused hr.applicant + Applicant <b>refused</b>