mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
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:
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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:
|
for contact_name in contact_names:
|
||||||
contact = frappe.get_doc('Contact', contact_name.get('name'))
|
contact = frappe.get_doc('Contact', contact_name.get('name'))
|
||||||
if not contact.has_link('Customer', self.name):
|
if not contact.has_link('Customer', self.name):
|
||||||
contact.append('links', dict(link_doctype='Customer', link_name=self.name))
|
contact.append('links', dict(link_doctype='Customer', link_name=self.name))
|
||||||
contact.save(ignore_permissions=self.flags.ignore_permissions)
|
contact.save(ignore_permissions=self.flags.ignore_permissions)
|
||||||
|
|
||||||
else:
|
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:])
|
||||||
|
|||||||
Reference in New Issue
Block a user