[fix] delete lead addresses in delete company transactions
diff --git a/erpnext/setup/doctype/company/delete_company_transactions.py b/erpnext/setup/doctype/company/delete_company_transactions.py
index ff6810d..f804f27 100644
--- a/erpnext/setup/doctype/company/delete_company_transactions.py
+++ b/erpnext/setup/doctype/company/delete_company_transactions.py
@@ -88,7 +88,8 @@
def delete_lead_addresses(company_name):
"""Delete addresses to which leads are linked"""
- frappe.db.sql("""delete from `tabAddress`
- where (customer='' or customer is null) and (supplier='' or supplier is null) and (lead != '' and lead is not null)""")
+ for lead in frappe.get_all("Lead", filters={"company": company_name}):
+ frappe.db.sql("""delete from `tabAddress`
+ where lead=%s and (customer='' or customer is null) and (supplier='' or supplier is null)""", lead.name)
- frappe.db.sql("""update `tabAddress` set lead=null, lead_name=null""")
+ frappe.db.sql("""update `tabAddress` set lead=null, lead_name=null where lead=%s""", lead.name)