diff --git a/frappe/model/naming.py b/frappe/model/naming.py index 1da27e577c..5eb6558405 100644 --- a/frappe/model/naming.py +++ b/frappe/model/naming.py @@ -230,7 +230,22 @@ def set_name_from_naming_options(autoname, doc): elif _autoname.startswith("format:"): doc.name = _format_autoname(autoname, doc) elif "#" in autoname: - doc.name = make_autoname(autoname, doc=doc) + # For Expression naming rule, first replace braced params, then normalize, then process series + # This handles patterns like {full_name}-{description}-.##### + def get_param_value_for_match(match): + param = match.group() + return parse_naming_series([param[1:-1]], doc=doc) + + # Replace braced params first + name_with_params = BRACED_PARAMS_PATTERN.sub(get_param_value_for_match, autoname) + + # Normalize pattern: convert '-.#####' to '.-.#####' to support both formats + # This handles cases like {fieldname}-.##### (without dot before dash) + # Pattern matches: dash followed by dot followed by one or more hashes, but only if not preceded by a dot + normalized_autoname = re.sub(r"(?