mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-26 22:52:10 +01:00
fix(customer): link contact and addresses if created from lead/opportunity/prospect
(cherry picked from commit 310099f4cd)
This commit is contained in:
@@ -232,7 +232,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()
|
||||||
@@ -272,15 +272,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"],
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user