From db01bf5dec74a190452b1c5a95fa59eba4db5c82 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 23 Mar 2023 12:58:32 +0530 Subject: [PATCH] fix: unset address and contact on trash (backport #34495) (#34560) fix: unset address and contact on trash (#34495) * fix(Customer): unset address and contact on trash * fix(Supplier): unset address and contact on trash --------- Co-authored-by: Sagar Sharma (cherry picked from commit f7bf1b8a0c3327a75d24b35db2abb438edf4a2c4) Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> --- erpnext/buying/doctype/supplier/supplier.py | 15 +++------------ erpnext/selling/doctype/customer/customer.py | 15 +++------------ 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index bebff1c3acbb..c96519a91538 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -128,18 +128,9 @@ def create_primary_address(self): 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 146ebbd7dfe8..0abbbcf0fc67 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -275,18 +275,9 @@ def validate_credit_limit_on_change(self): 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: