From d95559a53cb5084cfe1a3291cbafc700d18445c6 Mon Sep 17 00:00:00 2001
From: Ankush Menat <ankush@frappe.io>
Date: Fri, 14 Jul 2023 17:32:39 +0530
Subject: [PATCH] fix: patch for exotel

---
 erpnext/patches.txt                           |  3 +-
 .../exotel_integration_deprecation_warning.py | 10 -----
 .../v15_0/remove_exotel_integration.py        | 37 +++++++++++++++++++
 3 files changed, 39 insertions(+), 11 deletions(-)
 delete mode 100644 erpnext/patches/v13_0/exotel_integration_deprecation_warning.py
 create mode 100644 erpnext/patches/v15_0/remove_exotel_integration.py

diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index f9d9ebbdb3..6fa4b5a85a 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -333,4 +333,5 @@ execute:frappe.delete_doc('DocType', 'Cash Flow Mapping Accounts', ignore_missin
 erpnext.patches.v14_0.cleanup_workspaces
 erpnext.patches.v15_0.remove_loan_management_module #2023-07-03
 erpnext.patches.v14_0.set_report_in_process_SOA
-erpnext.buying.doctype.supplier.patches.migrate_supplier_portal_users
\ No newline at end of file
+erpnext.buying.doctype.supplier.patches.migrate_supplier_portal_users
+erpnext.patches.v15_0.remove_exotel_integration
diff --git a/erpnext/patches/v13_0/exotel_integration_deprecation_warning.py b/erpnext/patches/v13_0/exotel_integration_deprecation_warning.py
deleted file mode 100644
index 6e84ba9176..0000000000
--- a/erpnext/patches/v13_0/exotel_integration_deprecation_warning.py
+++ /dev/null
@@ -1,10 +0,0 @@
-import click
-
-
-def execute():
-
-	click.secho(
-		"Exotel integration is moved to a separate app and will be removed from ERPNext in version-14.\n"
-		"Please install the app to continue using the integration: https://github.com/frappe/exotel_integration",
-		fg="yellow",
-	)
diff --git a/erpnext/patches/v15_0/remove_exotel_integration.py b/erpnext/patches/v15_0/remove_exotel_integration.py
new file mode 100644
index 0000000000..a37773f337
--- /dev/null
+++ b/erpnext/patches/v15_0/remove_exotel_integration.py
@@ -0,0 +1,37 @@
+from contextlib import suppress
+
+import click
+import frappe
+from frappe import _
+from frappe.desk.doctype.notification_log.notification_log import make_notification_logs
+from frappe.utils.user import get_system_managers
+
+SETTINGS_DOCTYPE = "Exotel Settings"
+
+
+def execute():
+	if "exotel_integration" in frappe.get_installed_apps():
+		return
+
+	with suppress(Exception):
+		exotel = frappe.get_doc(SETTINGS_DOCTYPE)
+		if exotel.enabled:
+			notify_existing_users()
+
+		frappe.delete_doc("DocType", SETTINGS_DOCTYPE)
+
+
+def notify_existing_users():
+	click.secho(
+		"Exotel integration is moved to a separate app and will be removed from ERPNext in version-15.\n"
+		"Please install the app to continue using the integration: https://github.com/frappe/exotel_integration",
+		fg="yellow",
+	)
+
+	notification = {
+		"subject": _(
+			"WARNING: Exotel app has been separated from ERPNext, please install the app to continue using Exotel integration."
+		),
+		"type": "Alert",
+	}
+	make_notification_logs(notification, get_system_managers(only_name=True))