From b1d40de87eaeb8e579bab893db619c045bcfaa80 Mon Sep 17 00:00:00 2001 From: diptanilsaha Date: Fri, 21 Nov 2025 06:18:43 +0530 Subject: [PATCH] fix(customer): link contact and addresses if created from lead/opportunity/prospect (cherry picked from commit 310099f4cd7e1b14a8e81bf0cdcd3b747f49007a) --- erpnext/selling/doctype/customer/customer.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 9bebfa1e086..466009c772a 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -232,7 +232,7 @@ class Customer(TransactionBase): self.update_lead_status() if self.flags.is_new_doc: - self.link_lead_address_and_contact() + self.link_address_and_contact() self.copy_communication() self.update_customer_groups() @@ -272,15 +272,23 @@ class Customer(TransactionBase): if self.lead_name: frappe.db.set_value("Lead", self.lead_name, "status", "Converted") - def link_lead_address_and_contact(self): - if self.lead_name: - # assign lead address and contact to customer (if already not set) + def link_address_and_contact(self): + linked_documents = { + "Lead": self.lead_name, + "Opportunity": self.opportunity_name, + "Prospect": self.prospect_name, + } + for doctype, docname in linked_documents.items(): + # assign lead, opportunity and prospect address and contact to customer (if already not set) + if not docname: + continue + linked_contacts_and_addresses = frappe.get_all( "Dynamic Link", filters=[ ["parenttype", "in", ["Contact", "Address"]], - ["link_doctype", "=", "Lead"], - ["link_name", "=", self.lead_name], + ["link_doctype", "=", doctype], + ["link_name", "=", docname], ], fields=["parent as name", "parenttype as doctype"], )