def revert_series_if_last(key, name):
	if key in ".#":
		prefix, hashes = key.rsplit(".", 1)
		if "#" not in hashes:
			return
	else:
		prefix = key

	count = cint(name.replace(prefix, ""))
	current = frappe.db.sql("select `current` from `tabSeries` where name=%s for update", (prefix,))

	if current and current[0][0]==count:
		frappe.db.sql("update tabSeries set current=current-1 where name=%s", prefix)
dataset/ETHPy150Open frappe/frappe/frappe/model/naming.py/revert_series_if_last/swapped operands of `in`