From 795cf8544c6ee4bd572b284eee7eded219c3f82e Mon Sep 17 00:00:00 2001 From: diptanilsaha Date: Thu, 13 Aug 2026 22:44:23 +0530 Subject: [PATCH 1/2] fix(crm_settings): create custom fields for Frappe CRM on enabling synchronization (cherry picked from commit be2dea0ba2f108f388e39e316d95d4a83442a1a3) --- erpnext/crm/doctype/crm_settings/crm_settings.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/erpnext/crm/doctype/crm_settings/crm_settings.py b/erpnext/crm/doctype/crm_settings/crm_settings.py index 379c55ae5b3..73c0156e291 100644 --- a/erpnext/crm/doctype/crm_settings/crm_settings.py +++ b/erpnext/crm/doctype/crm_settings/crm_settings.py @@ -69,6 +69,13 @@ class CRMSettings(Document): self.allowed_users = [] def custom_fields_for_frappe_crm_data_sync(self): + custom_fields = self.get_frappe_crm_custom_fields() + + if self.enable_frappe_crm_data_synchronization: + create_custom_fields(custom_fields, ignore_validate=True) + + @staticmethod + def get_frappe_crm_custom_fields(): custom_fields = { "Quotation": [ { @@ -88,4 +95,4 @@ class CRMSettings(Document): ], } - create_custom_fields(custom_fields, ignore_validate=True) + return custom_fields From d66dc143e362492410337b552c7d91a5bd038462 Mon Sep 17 00:00:00 2001 From: diptanilsaha Date: Thu, 13 Aug 2026 22:51:24 +0530 Subject: [PATCH 2/2] fix: patch to delete the `crm_deal` custom fields (cherry picked from commit 9613d72d8182305148cf0fb4915cb013ea37839d) --- 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 df0f8071cbe..617441cab50 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -500,3 +500,4 @@ erpnext.patches.v16_0.rename_italy_customer_name_fields erpnext.patches.v16_0.set_stock_uom_in_job_card erpnext.patches.v16_0.recalculate_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)