[Fix] Not able to delete customer if contact is available
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index b17345c..2a6853a 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -173,6 +173,11 @@
frappe.throw(_("""New credit limit is less than current outstanding amount for the customer. Credit limit has to be atleast {0}""").format(outstanding_amt))
def on_trash(self):
+ if self.customer_primary_contact:
+ frappe.db.sql("""update `tabCustomer`
+ set customer_primary_contact=null, mobile_no=null, email_id=null
+ where name=%s""", self.name)
+
delete_contact_and_address('Customer', self.name)
if self.lead_name:
frappe.db.sql("update `tabLead` set status='Interested' where name=%s", self.lead_name)
diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py
index 45546e3..123fd55 100644
--- a/erpnext/selling/doctype/customer/test_customer.py
+++ b/erpnext/selling/doctype/customer/test_customer.py
@@ -96,6 +96,15 @@
so.save()
+ def test_delete_customer_contact(self):
+ customer = frappe.get_doc(
+ get_customer_dict('_Test Customer for delete')).insert(ignore_permissions=True)
+
+ customer.mobile_no = "8989889890"
+ customer.save()
+ self.assertTrue(customer.customer_primary_contact)
+ frappe.delete_doc('Customer', customer.name)
+
def test_disabled_customer(self):
make_test_records("Item")