Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions openupgrade_scripts/scripts/hr/16.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def create_work_contact(env):
res.user as a work_contact_id.

If the employee is not linked to a res.user. Then we try to match an
existing partner with the same email address. If one is found, then
we assign it as work_contact_id. If several are found, we raise a
warning and we link the first one found. If none are found, then we
create a new partner.
existing partner with the same email address and mobile (when the employee
has one of them). If one is found, then we assign it as work_contact_id.
If several are found, we raise a warning and we link the first one found.
If none are found, then we create a new partner.
"""
employees = env["hr.employee"].search([])

Expand All @@ -44,12 +44,17 @@ def create_work_contact(env):
partner.id,
)
else:
matching_partner = env["res.partner"].search(
[
("email", "=", employee.work_email),
("mobile", "=", employee.mobile_phone),
]
)
# Without email nor mobile, the search would match every partner
# that has neither of them, and an unrelated contact would become
# the work contact (the private address is merged into it in 17.0)
matching_partner = env["res.partner"]
if employee.work_email or employee.mobile_phone:
matching_partner = matching_partner.search(
[
("email", "=", employee.work_email),
("mobile", "=", employee.mobile_phone),
]
)
nb_matching_partner = len(matching_partner)
if nb_matching_partner == 1:
employee.work_contact_id = matching_partner
Expand Down
Loading