def set_title_field(self):
		def get_values():
			values = self.as_dict()
			# format values
			for key, value in values.iteritems():
				if value==None:
					values[key] = ""
			return values

		if self.meta.get("title_field")=="title":
			df = self.meta.get_field(self.meta.title_field)

			if df.options:
				self.set(df.fieldname, df.options.format(**get_values()))
			elif self.is_new() and not self.get(df.fieldname) and df.default:
				# set default title for new transactions (if default)
				self.set(df.fieldname, df.default.format(**get_values()))
Set title field based on template
dataset/ETHPy150Open frappe/frappe/frappe/model/document.py/Document.set_title_field