[FIX] crm: resolve NewId error on SO-Linked tasks

Issue:
    - When adding opportunity/lead to a contact using Studio
     and attempt to add a line, we encounter the following error:
     "TypeError: 'NewId' object is not iterable."

Steps To Reproduce (in 17.0):
    - In a contact form open Studio and add a O2M field
     Customer (Lead/Opportunity)
    - Try to add a line
    - Notice Traceback Error "TypeError: 'NewId' object is not iterable"

Solution:
    - The issue arises in the search domain of
    `return_if_relevant` , exactly in
    ("partner_id", "child_of", lead.partner_id.commercial_partner_id.id)
    where the type of `lead.partner_id.commercial_partner_id.id`
    is NewId since the partner is being edited to add a task.
    This action triggers the `parse` and `to_ids` methods with
    a value type of NewId. thus the error.

    - The operator child_of expects a list of IDs, and the ids
    property refer to the record's origin ids. to resolve this,
    replace `commercial_partner_id.id` with `commercial_partner_id.ids`.

opw-3760372

closes odoo/odoo#159296

Signed-off-by: Kawtar Drissi El Bouzaidi (kdeb) <kdeb@odoo.com>
This commit is contained in:
kdeb@odoo.com
2024-03-27 16:10:59 +00:00
parent 5df277fbc5
commit 03743a714f
+1 -1
View File
@@ -606,7 +606,7 @@ class Lead(models.Model):
# check for "same commercial entity" duplicates
if lead.partner_id and lead.partner_id.commercial_partner_id:
duplicate_lead_ids |= lead.with_context(active_test=False).search(common_lead_domain + [
("partner_id", "child_of", lead.partner_id.commercial_partner_id.id)
("partner_id", "child_of", lead.partner_id.commercial_partner_id.ids)
])
# check the phone number duplicates, based on phone_sanitized. Only
# exact matches are found, and the single one stored in phone_sanitized