diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 1190e85ca5..dfd8002e08 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -196,11 +196,17 @@ class DocType(Document): self.autoname = "naming_series:" # validate field name if autoname field:fieldname is used - + # Create unique index on autoname field automatically. if autoname and autoname.startswith('field:'): field = autoname.split(":")[1] if not field or field not in [ df.fieldname for df in self.fields ]: frappe.throw(_("Invalid fieldname '{0}' in autoname".format(field))) + else: + for df in self.fields: + if df.fieldname == field: + df.search_index = 1 + df.unique = 1 + break if autoname and (not autoname.startswith('field:')) \ and (not autoname.startswith('eval:')) \ @@ -835,4 +841,4 @@ def check_if_fieldname_conflicts_with_methods(doctype, fieldname): frappe.throw(_("Fieldname {0} conflicting with meta object").format(fieldname)) def clear_linked_doctype_cache(): - frappe.cache().delete_value('linked_doctypes_without_ignore_user_permissions_enabled') \ No newline at end of file + frappe.cache().delete_value('linked_doctypes_without_ignore_user_permissions_enabled')