From 7b7c6390f48690b444bfd7b828d6e4fdad716702 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 15 Dec 2025 12:01:39 +0530 Subject: [PATCH 1/2] fix!: Swap old style naming with new one "new" style of naming uses `format:` which is broken and unfixable. This commit discourages use of the new style. What was referred to as "old style" already works just fine and supports all the same things. ref https://github.com/frappe/frappe/issues/21212 --- cypress/integration/customize_form.js | 4 ++-- frappe/core/doctype/doctype/doctype.py | 12 ++++++++++++ frappe/public/js/frappe/doctype/index.js | 12 ++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cypress/integration/customize_form.js b/cypress/integration/customize_form.js index a072240993..bd4564964e 100644 --- a/cypress/integration/customize_form.js +++ b/cypress/integration/customize_form.js @@ -10,8 +10,8 @@ context("Customize Form", () => { const naming_rule_default_autoname_map = { "Set by user": "prompt", "By fieldname": "field:", - Expression: "format:", - "Expression (old style)": "", + Expression: "", + "Expression (old style)": "format:", Random: "hash", "By script": "", }; diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 2e2f28349b..bad1bf9ae6 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -216,6 +216,7 @@ class DocType(Document): self.validate_website() self.validate_virtual_doctype_methods() self.ensure_minimum_max_attachment_limit() + self.patch_old_naming_expressions() validate_links_table_fieldnames(self) if not self.is_new(): @@ -447,6 +448,17 @@ class DocType(Document): alert=True, ) + def patch_old_naming_expressions(self): + if not self.autoname: + return + + # We swapped naming_rule field old/new to discourage use of "format:" + if self.autoname and self.autoname.startswith("format:"): + self.naming_rule = "Expression (old style)" + + if self.naming_rule == "Expression (old style)" and not self.autoname.startswith("format:"): + self.naming_rule = "Expression" + def change_modified_of_parent(self): """Change the timestamp of parent DocType if the current one is a child to clear caches.""" if frappe.flags.in_import: diff --git a/frappe/public/js/frappe/doctype/index.js b/frappe/public/js/frappe/doctype/index.js index 4d8e437c1b..2502fadb5b 100644 --- a/frappe/public/js/frappe/doctype/index.js +++ b/frappe/public/js/frappe/doctype/index.js @@ -75,8 +75,8 @@ frappe.model.DocTypeController = class DocTypeController extends frappe.ui.form. "Set by user": "prompt", "By fieldname": "field:", 'By "Naming Series" field': "naming_series:", - Expression: "format:", - "Expression (sld style)": "", + Expression: "", + "Expression (old style)": "format:", Random: "hash", UUID: "UUID", "By script": "", @@ -99,9 +99,9 @@ frappe.model.DocTypeController = class DocTypeController extends frappe.ui.form. "By fieldname": "Format: field:[fieldname]. Valid fieldname must exist", 'By "Naming Series" field': "Format: naming_series:[fieldname]. Default fieldname is naming_series", - Expression: - "Format: format:EXAMPLE-{MM}morewords{fieldname1}-{fieldname2}-{#####} - Replace all braced words (fieldnames, date words (DD, MM, YY), series) with their value. Outside braces, any characters can be used.", "Expression (old style)": + "Format: format:EXAMPLE-{MM}morewords{fieldname1}-{fieldname2}-{#####} - Replace all braced words (fieldnames, date words (DD, MM, YY), series) with their value. Outside braces, any characters can be used.", + Expression: "Format: EXAMPLE-.##### Series by prefix (separated by a dot)", Random: "", "By script": "", @@ -129,9 +129,9 @@ frappe.model.DocTypeController = class DocTypeController extends frappe.ui.form. else if (autoname.startsWith("naming_series:")) this.frm.set_value("naming_rule", 'By "Naming Series" field'); else if (autoname.startsWith("format:")) - this.frm.set_value("naming_rule", "Expression"); + this.frm.set_value("naming_rule", "Expression (old style)"); else if (autoname === "hash") this.frm.set_value("naming_rule", "Random"); - else this.frm.set_value("naming_rule", "Expression (old style)"); + else this.frm.set_value("naming_rule", "Expression"); setTimeout(() => (this.frm.__from_autoname = false), 500); } From 192fd21634e4f976612837d52d99cf4255b5a8cf Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 15 Dec 2025 12:21:26 +0530 Subject: [PATCH 2/2] fix: Remove old option from UI It will continue to work in DB and logic by setting `format:` prefix. --- frappe/core/doctype/doctype/doctype.py | 1 + frappe/public/js/frappe/doctype/index.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index bad1bf9ae6..9323d7c69f 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -455,6 +455,7 @@ class DocType(Document): # We swapped naming_rule field old/new to discourage use of "format:" if self.autoname and self.autoname.startswith("format:"): self.naming_rule = "Expression (old style)" + frappe.toast(_("Warning: Usage of 'format:' is discouraged."), indicator="yellow") if self.naming_rule == "Expression (old style)" and not self.autoname.startswith("format:"): self.naming_rule = "Expression" diff --git a/frappe/public/js/frappe/doctype/index.js b/frappe/public/js/frappe/doctype/index.js index 2502fadb5b..f06ab54876 100644 --- a/frappe/public/js/frappe/doctype/index.js +++ b/frappe/public/js/frappe/doctype/index.js @@ -24,6 +24,7 @@ frappe.model.DocTypeController = class DocTypeController extends frappe.ui.form. refresh() { this.show_db_utilization(); + this.remove_old_style_naming_option(); } show_db_utilization() { @@ -45,6 +46,12 @@ frappe.model.DocTypeController = class DocTypeController extends frappe.ui.form. }); } + remove_old_style_naming_option() { + let df = this.frm.get_docfield("naming_rule"); + df.options = df.options.replace("Expression (old style)\n", ""); + this.frm.refresh_field("naming_rule"); + } + max_attachments() { if (!this.frm.doc.max_attachments) { return;