From 94320a9928fb98787d30e263e362609cce460985 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Tue, 11 Aug 2026 16:09:08 +0530 Subject: [PATCH] perf: rewrite customer and supplier naming setters only on change Every Selling Settings save reran set_by_naming_series for Customer and every Buying Settings save reran it for Supplier, rewriting the naming_series property setters with their cache clears and running the naming_series backfill UPDATE on the master table. Gate both on has_value_changed, following Stock Settings. Naming behaviour is unaffected: Customer.autoname and Supplier.autoname read the master-name default, which is still set on every save. --- .../buying_settings/buying_settings.py | 12 +++++++--- .../selling_settings/selling_settings.py | 22 ++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/erpnext/buying/doctype/buying_settings/buying_settings.py b/erpnext/buying/doctype/buying_settings/buying_settings.py index 91ba900873b..d4f32e7cb2b 100644 --- a/erpnext/buying/doctype/buying_settings/buying_settings.py +++ b/erpnext/buying/doctype/buying_settings/buying_settings.py @@ -53,6 +53,15 @@ class BuyingSettings(Document): for key in ["supplier_group", "supp_master_name", "maintain_same_rate", "buying_price_list"]: frappe.db.set_default(key, self.get(key, "")) + self.update_supplier_naming_settings() + + if not self.bill_for_rejected_quantity_in_purchase_invoice: + self.set_valuation_rate_for_rejected_materials = 0 + + def update_supplier_naming_settings(self): + if not self.has_value_changed("supp_master_name"): + return + from erpnext.utilities.naming import set_by_naming_series set_by_naming_series( @@ -62,9 +71,6 @@ class BuyingSettings(Document): hide_name_field=False, ) - if not self.bill_for_rejected_quantity_in_purchase_invoice: - self.set_valuation_rate_for_rejected_materials = 0 - def before_save(self): self.check_maintain_same_rate() diff --git a/erpnext/selling/doctype/selling_settings/selling_settings.py b/erpnext/selling/doctype/selling_settings/selling_settings.py index 66e4bf5d93a..70c57579cb2 100644 --- a/erpnext/selling/doctype/selling_settings/selling_settings.py +++ b/erpnext/selling/doctype/selling_settings/selling_settings.py @@ -84,14 +84,7 @@ class SellingSettings(Document): ]: frappe.db.set_default(key, self.get(key, "")) - from erpnext.utilities.naming import set_by_naming_series - - set_by_naming_series( - "Customer", - "customer_name", - self.get("cust_master_name") == "Naming Series", - hide_name_field=False, - ) + self.update_customer_naming_settings() self.validate_fallback_to_default_price_list() @@ -101,6 +94,19 @@ class SellingSettings(Document): if old_doc and old_doc.enable_utm != self.enable_utm: toggle_utm_analytics_section(not self.enable_utm) + def update_customer_naming_settings(self): + if not self.has_value_changed("cust_master_name"): + return + + from erpnext.utilities.naming import set_by_naming_series + + set_by_naming_series( + "Customer", + "customer_name", + self.get("cust_master_name") == "Naming Series", + hide_name_field=False, + ) + def validate_fallback_to_default_price_list(self): if ( self.fallback_to_default_price_list