[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 <kba@odoo.com>
This commit is contained in:
sofiagvaladze
2023-06-06 09:19:23 +02:00
parent 2af270d76a
commit 4a68ec46ec
+7 -4
View File
@@ -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):