diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index 120b2f8bbe..01b5c8f064 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -125,18 +125,9 @@ class Supplier(TransactionBase): def on_trash(self): if self.supplier_primary_contact: - frappe.db.sql( - """ - UPDATE `tabSupplier` - SET - supplier_primary_contact=null, - supplier_primary_address=null, - mobile_no=null, - email_id=null, - primary_address=null - WHERE name=%(name)s""", - {"name": self.name}, - ) + self.db_set("supplier_primary_contact", None) + if self.supplier_primary_address: + self.db_set("supplier_primary_address", None) delete_contact_and_address("Supplier", self.name) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index d9dab33501..baa316f681 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -272,18 +272,9 @@ class Customer(TransactionBase): def on_trash(self): if self.customer_primary_contact: - frappe.db.sql( - """ - UPDATE `tabCustomer` - SET - customer_primary_contact=null, - customer_primary_address=null, - mobile_no=null, - email_id=null, - primary_address=null - WHERE name=%(name)s""", - {"name": self.name}, - ) + self.db_set("customer_primary_contact", None) + if self.customer_primary_address: + self.db_set("customer_primary_address", None) delete_contact_and_address("Customer", self.name) if self.lead_name: