fix(customer): link contact and addresses if created from lead/opportunity/prospect

This commit is contained in:
diptanilsaha
2025-11-21 06:18:43 +05:30
parent ee69a6b8ab
commit 310099f4cd

View File

@@ -235,7 +235,7 @@ class Customer(TransactionBase):
self.update_lead_status() self.update_lead_status()
if self.flags.is_new_doc: if self.flags.is_new_doc:
self.link_lead_address_and_contact() self.link_address_and_contact()
self.copy_communication() self.copy_communication()
self.update_customer_groups() self.update_customer_groups()
@@ -279,15 +279,23 @@ class Customer(TransactionBase):
if self.lead_name: if self.lead_name:
frappe.db.set_value("Lead", self.lead_name, "status", "Converted") frappe.db.set_value("Lead", self.lead_name, "status", "Converted")
def link_lead_address_and_contact(self): def link_address_and_contact(self):
if self.lead_name: linked_documents = {
# assign lead address and contact to customer (if already not set) "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( linked_contacts_and_addresses = frappe.get_all(
"Dynamic Link", "Dynamic Link",
filters=[ filters=[
["parenttype", "in", ["Contact", "Address"]], ["parenttype", "in", ["Contact", "Address"]],
["link_doctype", "=", "Lead"], ["link_doctype", "=", doctype],
["link_name", "=", self.lead_name], ["link_name", "=", docname],
], ],
fields=["parent as name", "parenttype as doctype"], fields=["parent as name", "parenttype as doctype"],
) )