Automatically create unique index on autoname field (#5674)
* Automatically create unique index on autoname field * Update doctype.py * Indentation fix.
This commit is contained in:
parent
2489bf4c7a
commit
e47b03af69
1 changed files with 8 additions and 2 deletions
|
|
@ -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')
|
||||
frappe.cache().delete_value('linked_doctypes_without_ignore_user_permissions_enabled')
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue