From 4a68ec46ec8928dd8ea5ac9b04b04eac1a3a2278 Mon Sep 17 00:00:00 2001 From: sofiagvaladze Date: Fri, 28 Apr 2023 09:21:49 +0000 Subject: [PATCH] [IMP] hr_recruitment: avoid sending stage change message to unarchived applicants Purpose: When the applicant is unarchived, they are automatically set back to first stage. This is done automatically. In case there is automated message post configured for that stage change, it will send the mail to the applicant. We want to avoid this. After this commit, the automated message related to the stage change will not be posted in case the applicant has been just unarchived, even if it is configured for the stage. task - 3267915 closes odoo/odoo#120506 Signed-off-by: Kevin Baptiste --- addons/hr_recruitment/models/hr_applicant.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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):