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.
This commit is contained in:
Nabin Hait
2026-06-22 13:05:50 +05:30
parent c4bbf22c62
commit f1b6a7d690
3 changed files with 15 additions and 2 deletions

View File

@@ -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 = (

View File

@@ -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

View File

@@ -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)