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);
}