Browse Source

fix: contact duplication on converting lead to customer (#29001)

* fix: contact duplication on converting lead to customer

* fix: added test case
develop
Anupam Kumar 3 years ago
committed by GitHub
parent
commit
cfb6b26e47
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      erpnext/crm/doctype/lead/test_lead.py
  2. 25
      erpnext/selling/doctype/customer/customer.py

11
erpnext/crm/doctype/lead/test_lead.py

@ -23,6 +23,17 @@ class TestLead(unittest.TestCase):
customer.customer_group = "_Test Customer Group" customer.customer_group = "_Test Customer Group"
customer.insert() 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): def test_make_customer_from_organization(self):
from erpnext.crm.doctype.lead.lead import make_customer from erpnext.crm.doctype.lead.lead import make_customer

25
erpnext/selling/doctype/customer/customer.py

@ -196,20 +196,19 @@ class Customer(TransactionBase):
if not lead.lead_name: if not lead.lead_name:
frappe.throw(_("Please mention the Lead Name in Lead {0}").format(self.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={
contact_names = frappe.get_all('Dynamic Link', filters={ "parenttype":"Contact",
"parenttype":"Contact", "link_doctype":"Lead",
"link_doctype":"Lead", "link_name":self.lead_name
"link_name":self.lead_name }, fields=["parent as 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)
else: 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)
if not contact_names:
lead.lead_name = lead.lead_name.lstrip().split(" ") lead.lead_name = lead.lead_name.lstrip().split(" ")
lead.first_name = lead.lead_name[0] lead.first_name = lead.lead_name[0]
lead.last_name = " ".join(lead.lead_name[1:]) lead.last_name = " ".join(lead.lead_name[1:])

Loading…
Cancel
Save