From 97b67cfed5df2f40c119cd766fdb497f79cf6733 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Sun, 19 Jan 2025 16:13:18 +0530 Subject: [PATCH] patch: Rename Twilio Settings to CRM Twilio Settings Move Twilio Agent to Telephony Agent --- crm/patches.txt | 4 ++- .../move_twilio_agent_to_telephony_agent.py | 27 +++++++++++++++++++ ..._twilio_settings_to_crm_twilio_settings.py | 11 ++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 crm/patches/v1_0/move_twilio_agent_to_telephony_agent.py create mode 100644 crm/patches/v1_0/rename_twilio_settings_to_crm_twilio_settings.py diff --git a/crm/patches.txt b/crm/patches.txt index f964d13f..f8fbb4c6 100644 --- a/crm/patches.txt +++ b/crm/patches.txt @@ -2,6 +2,7 @@ # Patches added in this section will be executed before doctypes are migrated # Read docs to understand patches: https://frappeframework.com/docs/v14/user/en/database-migrations crm.patches.v1_0.move_crm_note_data_to_fcrm_note +crm.patches.v1_0.rename_twilio_settings_to_crm_twilio_settings [post_model_sync] # Patches added in this section will be executed after doctypes are migrated @@ -9,4 +10,5 @@ crm.patches.v1_0.create_email_template_custom_fields crm.patches.v1_0.create_default_fields_layout #10/12/2024 crm.patches.v1_0.create_default_sidebar_fields_layout crm.patches.v1_0.update_deal_quick_entry_layout -crm.patches.v1_0.update_layouts_to_new_format \ No newline at end of file +crm.patches.v1_0.update_layouts_to_new_format +crm.patches.v1_0.move_twilio_agent_to_telephony_agent \ No newline at end of file diff --git a/crm/patches/v1_0/move_twilio_agent_to_telephony_agent.py b/crm/patches/v1_0/move_twilio_agent_to_telephony_agent.py new file mode 100644 index 00000000..7049ab62 --- /dev/null +++ b/crm/patches/v1_0/move_twilio_agent_to_telephony_agent.py @@ -0,0 +1,27 @@ +import frappe + + +def execute(): + if not frappe.db.exists("DocType", "CRM Telephony Agent"): + frappe.reload_doctype("CRM Telephony Agent", force=True) + + if frappe.db.exists("DocType", "Twilio Agents") and frappe.db.count("Twilio Agents") == 0: + return + + agents = frappe.db.sql("SELECT * FROM `tabTwilio Agents`", as_dict=True) + if agents: + for agent in agents: + doc = frappe.get_doc( + { + "doctype": "CRM Telephony Agent", + "creation": agent.get("creation"), + "modified": agent.get("modified"), + "modified_by": agent.get("modified_by"), + "owner": agent.get("owner"), + "user": agent.get("user"), + "twilio_number": agent.get("twilio_number"), + "user_name": agent.get("user_name"), + "twilio": True, + } + ) + doc.db_insert() diff --git a/crm/patches/v1_0/rename_twilio_settings_to_crm_twilio_settings.py b/crm/patches/v1_0/rename_twilio_settings_to_crm_twilio_settings.py new file mode 100644 index 00000000..0a12973d --- /dev/null +++ b/crm/patches/v1_0/rename_twilio_settings_to_crm_twilio_settings.py @@ -0,0 +1,11 @@ +import frappe +from frappe.model.rename_doc import rename_doc + + +def execute(): + if frappe.db.table_exists("Twilio Settings"): + frappe.flags.ignore_route_conflict_validation = True + rename_doc("DocType", "Twilio Settings", "CRM Twilio Settings") + frappe.flags.ignore_route_conflict_validation = False + + frappe.reload_doctype("CRM Twilio Settings", force=True)