diff --git a/erpnext/crm/doctype/lead/test_lead.py b/erpnext/crm/doctype/lead/test_lead.py index 56bfc8f145..3882974022 100644 --- a/erpnext/crm/doctype/lead/test_lead.py +++ b/erpnext/crm/doctype/lead/test_lead.py @@ -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 diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 0c8c53aabe..b7f74df105 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -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"]) - - 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) + contact_names = frappe.get_all('Dynamic Link', filters={ + "parenttype":"Contact", + "link_doctype":"Lead", + "link_name":self.lead_name + }, fields=["parent as name"]) - 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.first_name = lead.lead_name[0] lead.last_name = " ".join(lead.lead_name[1:])