[FIX] hr_recruitment: synchro of data between partner and hr.applicant
Previously, when receiving a new email to create a job applicant for an existing partner, the process would inadvertently erase the phone and mobile numbers on the partner by using the inverse method. With this commit, the behavior is adjusted so that phone numbers are only written in the inverse method on the partner if there is a number present on the applicant. This prevents the inadvertent removal of phone numbers on the partner when creating new applicants for existing partners. Additionally, this commit ensures that phone numbers from the partner are computed on the applicant as if they were related non-stored fields. This avoids the need for manual re-encoding of numbers later and prevents the inverse method from being forced again. Furthermore, to optimize the process, email changes are now only processed using the inverse method if the normalized version of the email is different. This prevents unnecessary method calls on the highly used res.partner model when the email is updated, particularly for cases where the normalized version remains the same. Previously, changing the partner's email from `jke@odoo.com` to `"JKE" jke@odoo.com` would resend all waiting sign requests because the normalized versions of the email were distinct. While ideally, this check could be performed within the sign request code itself, this optimization now helps prevent unnecessary overrides across all modules simultaneously. closes odoo/odoo#163495 Signed-off-by: Bertrand Dossogne (bedo) <bedo@odoo.com>
This commit is contained in:
@@ -328,9 +328,15 @@ class Applicant(models.Model):
|
||||
'phone': applicant.partner_phone,
|
||||
})
|
||||
else:
|
||||
applicant.partner_id.email = applicant.email_from
|
||||
applicant.partner_id.mobile = applicant.partner_mobile
|
||||
applicant.partner_id.phone = applicant.partner_phone
|
||||
if applicant.email_from and \
|
||||
tools.email_normalize(applicant.email_from) != tools.email_normalize(applicant.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>""
|
||||
applicant.partner_id.email = applicant.email_from
|
||||
if applicant.partner_mobile:
|
||||
applicant.partner_id.mobile = applicant.partner_mobile
|
||||
if applicant.partner_phone:
|
||||
applicant.partner_id.phone = applicant.partner_phone
|
||||
|
||||
@api.depends('partner_phone')
|
||||
def _compute_partner_phone_sanitized(self):
|
||||
@@ -612,7 +618,9 @@ class Applicant(models.Model):
|
||||
defaults['stage_id'] = stage.id
|
||||
if custom_values:
|
||||
defaults.update(custom_values)
|
||||
return super(Applicant, self).message_new(msg, custom_values=defaults)
|
||||
res = super().message_new(msg, custom_values=defaults)
|
||||
res._compute_partner_phone_email()
|
||||
return res
|
||||
|
||||
def _message_post_after_hook(self, message, msg_vals):
|
||||
if self.email_from and not self.partner_id:
|
||||
|
||||
Reference in New Issue
Block a user