diff --git a/addons/hr_recruitment/models/hr_applicant.py b/addons/hr_recruitment/models/hr_applicant.py index 3290f8f8065..15d84510fde 100644 --- a/addons/hr_recruitment/models/hr_applicant.py +++ b/addons/hr_recruitment/models/hr_applicant.py @@ -455,7 +455,9 @@ class Applicant(models.Model): def _track_template(self, changes): res = super(Applicant, self)._track_template(changes) applicant = self[0] - if 'stage_id' in changes and applicant.stage_id.template_id: + # When applcant is unarchived, they are put back to the default stage automatically. In this case, + # don't post automated message related to the stage change. + if 'stage_id' in changes and applicant.stage_id.template_id and not applicant._context.get('just_unarchived'): res['stage_id'] = (applicant.stage_id.template_id, { 'auto_delete_keep_log': False, 'subtype_id': self.env['ir.model.data']._xmlid_to_res_id('mail.mt_note'), @@ -619,10 +621,11 @@ class Applicant(models.Model): 'refuse_reason_id': False}) def toggle_active(self): + self = self.with_context(just_unarchived=True) res = super(Applicant, self).toggle_active() - applicant_active = self.filtered(lambda applicant: applicant.active) - if applicant_active: - applicant_active.reset_applicant() + active_applicants = self.filtered(lambda applicant: applicant.active) + if active_applicants: + active_applicants.reset_applicant() return res def action_send_email(self):