From f1b6a7d6907323fc84f5bbb0d43002358c288acb Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 22 Jun 2026 13:05:50 +0530 Subject: [PATCH] fix(crm): drive opportunity auto-close days from CRM Settings, not a hardcoded fallback auto_close_opportunity fell back to 15 days in code when the CRM Setting was blank (and its docstring still said 7). The field already defaults to 15, so read the value straight from CRM Settings and add a patch to backfill 15 for existing sites that left it blank, keeping the same auto-close schedule. --- erpnext/crm/doctype/opportunity/opportunity.py | 4 ++-- erpnext/patches.txt | 1 + .../set_default_close_opportunity_after_days.py | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 erpnext/patches/v16_0/set_default_close_opportunity_after_days.py diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index ede7271132f..84ac1f4d300 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -399,8 +399,8 @@ def set_multiple_status(names: str | list[str], status: str): def auto_close_opportunity(): - """auto close the `Replied` Opportunities after 7 days""" - auto_close_after_days = frappe.db.get_single_value("CRM Settings", "close_opportunity_after_days") or 15 + """Auto close `Replied` Opportunities inactive for the days configured in CRM Settings.""" + auto_close_after_days = frappe.db.get_single_value("CRM Settings", "close_opportunity_after_days") table = frappe.qb.DocType("Opportunity") opportunities = ( diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 5db549806a3..65687c7c118 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -489,3 +489,4 @@ erpnext.patches.v16_0.submit_existing_product_bundles #1 erpnext.patches.v16_0.migrate_subscription_generate_invoice_at erpnext.patches.v16_0.rename_subscription_billing_period_fields erpnext.patches.v16_0.drop_redundant_serial_no_index_from_sabb +erpnext.patches.v16_0.set_default_close_opportunity_after_days diff --git a/erpnext/patches/v16_0/set_default_close_opportunity_after_days.py b/erpnext/patches/v16_0/set_default_close_opportunity_after_days.py new file mode 100644 index 00000000000..736b584e1de --- /dev/null +++ b/erpnext/patches/v16_0/set_default_close_opportunity_after_days.py @@ -0,0 +1,12 @@ +import frappe + + +def execute(): + """Backfill the default for CRM Settings.close_opportunity_after_days. + + The auto-close logic used to fall back to 15 days in code. Now that the fallback is removed, + existing sites that never set the value (left blank / 0) need it filled in so opportunities + keep auto-closing on the same schedule. + """ + if not frappe.db.get_single_value("CRM Settings", "close_opportunity_after_days"): + frappe.db.set_single_value("CRM Settings", "close_opportunity_after_days", 15)