From 9613d72d8182305148cf0fb4915cb013ea37839d Mon Sep 17 00:00:00 2001 From: diptanilsaha Date: Thu, 13 Aug 2026 22:51:24 +0530 Subject: [PATCH] fix: patch to delete the `crm_deal` custom fields --- erpnext/patches.txt | 1 + .../v16_0/remove_frappe_crm_custom_fields.py | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 erpnext/patches/v16_0/remove_frappe_crm_custom_fields.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index e023cff4b3f..d5eb474d62e 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -513,3 +513,4 @@ erpnext.patches.v16_0.rename_italy_customer_name_fields erpnext.patches.v16_0.recalculate_purchase_receipt_billing_status erpnext.patches.v16_0.recalculate_mixed_purchase_receipt_billing_status erpnext.patches.v16_0.repair_work_order_material_transfer +erpnext.patches.v16_0.remove_frappe_crm_custom_fields diff --git a/erpnext/patches/v16_0/remove_frappe_crm_custom_fields.py b/erpnext/patches/v16_0/remove_frappe_crm_custom_fields.py new file mode 100644 index 00000000000..3f1c8e1a6f4 --- /dev/null +++ b/erpnext/patches/v16_0/remove_frappe_crm_custom_fields.py @@ -0,0 +1,27 @@ +import frappe +from frappe.custom.doctype.custom_field.custom_field import delete_custom_fields + +from erpnext.crm.doctype.crm_settings.crm_settings import CRMSettings + + +def execute(): + """Delete the `crm_deal` fields on Quotation and Customer if Frappe CRM Data Synchronization is disabled and there's no data on those fields.""" + + crm_deal_exists_in_quotation = frappe.db.has_column("Quotation", "crm_deal") and frappe.get_all( + "Quotation", filters={"crm_deal": ["is", "set"]}, limit=1 + ) + + crm_deal_exists_in_customer = frappe.db.has_column("Customer", "crm_deal") and frappe.get_all( + "Customer", filters={"crm_deal": ["is", "set"]}, limit=1 + ) + + enable_frappe_crm_data_sync = frappe.get_single_value( + "CRM Settings", "enable_frappe_crm_data_synchronization" + ) + + if enable_frappe_crm_data_sync or crm_deal_exists_in_quotation or crm_deal_exists_in_customer: + return + + custom_fields = CRMSettings.get_frappe_crm_custom_fields() + + delete_custom_fields(custom_fields)