From 54d85900643eef286e1c42d69958c94a6f63b53b Mon Sep 17 00:00:00 2001 From: shreyas Date: Mon, 17 Oct 2016 14:25:20 +0530 Subject: [PATCH] [Fix] Delete communications when user deletes company transactions --- .../doctype/company/delete_company_transactions.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/company/delete_company_transactions.py b/erpnext/setup/doctype/company/delete_company_transactions.py index 8f058e86ed..e5196d167b 100644 --- a/erpnext/setup/doctype/company/delete_company_transactions.py +++ b/erpnext/setup/doctype/company/delete_company_transactions.py @@ -14,7 +14,7 @@ def delete_company_transactions(company_name): doc = frappe.get_doc("Company", company_name) if frappe.session.user != doc.owner: - frappe.throw(_("Transactions can only be deleted by the creator of the Company"), + frappe.throw(_("Transactions can only be deleted by the creator of the Company"), frappe.PermissionError) delete_bins(company_name) @@ -64,6 +64,16 @@ def delete_for_doctype(doctype, company_name): frappe.db.sql("""update tabSeries set current = %s where name=%s""", (last, prefix)) + # delete communication + try: + frappe.db.sql(""" + select name, reference_doctype from `tabCommunication` + where reference_doctype = "{0}" and + exists(select name from `tab{1}` where company = %s and + `tabCommunication`.reference_name = name) + """.format(doctype, doctype), company_name) + except Exception, e: + print e def delete_bins(company_name): frappe.db.sql("""delete from tabBin where warehouse in