Fix Change Candidate _inverse_partner_email

This commit is contained in:
Pranay 2025-04-21 13:22:54 +05:30 committed by raman
parent c225eeec5d
commit 7b91e82363
1 changed files with 19 additions and 0 deletions

View File

@ -48,6 +48,25 @@ class HrCandidate(models.Model):
rec.resume_type = '' rec.resume_type = ''
rec.resume_name = '' rec.resume_name = ''
def _inverse_partner_email(self):
for candidate in self:
if not candidate.email_from:
continue
if not candidate.partner_id:
if not candidate.partner_name:
raise UserError(_('You must define a Contact Name for this candidate.'))
candidate.partner_id = self.env['res.partner'].sudo().with_context(default_lang=self.env.lang).find_or_create(candidate.email_from)
if candidate.partner_name and not candidate.sudo().partner_id.name:
candidate.sudo().partner_id.name = candidate.partner_name
if tools.email_normalize(candidate.email_from) != tools.email_normalize(candidate.sudo().partner_id.email):
# change email on a partner will trigger other heavy code, so avoid to change the email when
# it is the same. E.g. "email@example.com" vs "My Email" <email@example.com>""
candidate.sudo().partner_id.email = candidate.email_from
if candidate.partner_phone:
candidate.sudo().partner_id.phone = candidate.partner_phone
def action_open_applications(self): def action_open_applications(self):
self.ensure_one() self.ensure_one()
return { return {