fix: contact duplication on converting lead to customer (#29001)
* fix: contact duplication on converting lead to customer * fix: added test case
This commit is contained in:
parent
9c4455f77c
commit
cfb6b26e47
@ -23,6 +23,17 @@ class TestLead(unittest.TestCase):
|
||||
customer.customer_group = "_Test Customer Group"
|
||||
customer.insert()
|
||||
|
||||
#check whether lead contact is carried forward to the customer.
|
||||
contact = frappe.db.get_value('Dynamic Link', {
|
||||
"parenttype": "Contact",
|
||||
"link_doctype": "Lead",
|
||||
"link_name": customer.lead_name,
|
||||
}, "parent")
|
||||
|
||||
if contact:
|
||||
contact_doc = frappe.get_doc("Contact", contact)
|
||||
self.assertEqual(contact_doc.has_link(customer.doctype, customer.name), True)
|
||||
|
||||
def test_make_customer_from_organization(self):
|
||||
from erpnext.crm.doctype.lead.lead import make_customer
|
||||
|
||||
|
@ -196,20 +196,19 @@ class Customer(TransactionBase):
|
||||
if not lead.lead_name:
|
||||
frappe.throw(_("Please mention the Lead Name in Lead {0}").format(self.lead_name))
|
||||
|
||||
if lead.company_name:
|
||||
contact_names = frappe.get_all('Dynamic Link', filters={
|
||||
"parenttype":"Contact",
|
||||
"link_doctype":"Lead",
|
||||
"link_name":self.lead_name
|
||||
}, fields=["parent as name"])
|
||||
contact_names = frappe.get_all('Dynamic Link', filters={
|
||||
"parenttype":"Contact",
|
||||
"link_doctype":"Lead",
|
||||
"link_name":self.lead_name
|
||||
}, fields=["parent as name"])
|
||||
|
||||
for contact_name in contact_names:
|
||||
contact = frappe.get_doc('Contact', contact_name.get('name'))
|
||||
if not contact.has_link('Customer', self.name):
|
||||
contact.append('links', dict(link_doctype='Customer', link_name=self.name))
|
||||
contact.save(ignore_permissions=self.flags.ignore_permissions)
|
||||
for contact_name in contact_names:
|
||||
contact = frappe.get_doc('Contact', contact_name.get('name'))
|
||||
if not contact.has_link('Customer', self.name):
|
||||
contact.append('links', dict(link_doctype='Customer', link_name=self.name))
|
||||
contact.save(ignore_permissions=self.flags.ignore_permissions)
|
||||
|
||||
else:
|
||||
if not contact_names:
|
||||
lead.lead_name = lead.lead_name.lstrip().split(" ")
|
||||
lead.first_name = lead.lead_name[0]
|
||||
lead.last_name = " ".join(lead.lead_name[1:])
|
||||
|
Loading…
x
Reference in New Issue
Block a user