def set_new_name(doc):
	"""Sets the `name`` property for the document based on various rules.

	1. If amened doc, set suffix.
	3. If `autoname` method is declared, then call it.
	4. If `autoname` property is set in the DocType (`meta`), then build it using the `autoname` property.
	2. If `name` is already defined, use that name
	5. If no rule defined, use hash.

	#### Note:

	:param doc: Document to be named."""

	doc.run_method("before_naming")

	autoname = frappe.get_meta(doc.doctype).autoname
	if getattr(doc, "amended_from", None):
		_set_amended_name(doc)
		return

	elif getattr(doc.meta, "issingle", False):
		doc.name = doc.doctype

	elif hasattr(doc, "autoname"):
		doc.run_method("autoname")

	elif autoname:
		if autoname.startswith('field:'):
			fieldname = autoname[6:]
			doc.name = (doc.get(fieldname) or "").strip()
			if not doc.name:
				frappe.throw(_("{0} is required").format(doc.meta.get_label(fieldname)))
				raise Exception, 'Name is required'
		if autoname.startswith("naming_series:"):
			set_name_by_naming_series(doc)
		elif autoname in "#":
			doc.name = make_autoname(autoname)
		elif autoname=='Prompt':
			# set from __newname in save.py
			if not doc.name:
				frappe.throw(_("Name not set via Prompt"))

	if not doc.name or autoname=='hash':
		doc.name = make_autoname('hash', doc.doctype)

	doc.name = validate_name(doc.doctype, doc.name)
dataset/ETHPy150Open frappe/frappe/frappe/model/naming.py/set_new_name/swapped operands of `in`