Merge pull request #12810 from nextchamp-saqib/naming-series-fix

fix: reverting of series with a variable
This commit is contained in:
mergify[bot] 2021-04-07 06:38:20 +00:00 committed by GitHub
commit d2a432bd65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -157,10 +157,10 @@ def update_naming_series(doc):
if doc.meta.autoname:
if doc.meta.autoname.startswith("naming_series:") \
and getattr(doc, "naming_series", None):
revert_series_if_last(doc.naming_series, doc.name)
revert_series_if_last(doc.naming_series, doc.name, doc)
elif doc.meta.autoname.split(":")[0] not in ("Prompt", "field", "hash"):
revert_series_if_last(doc.meta.autoname, doc.name)
revert_series_if_last(doc.meta.autoname, doc.name, doc)
def delete_from_table(doctype, name, ignore_doctypes, doc):
if doctype!="DocType" and doctype==name:

View file

@ -198,7 +198,7 @@ def getseries(key, digits):
return ('%0'+str(digits)+'d') % current
def revert_series_if_last(key, name):
def revert_series_if_last(key, name, doc=None):
if ".#" in key:
prefix, hashes = key.rsplit(".", 1)
if "#" not in hashes:
@ -207,7 +207,7 @@ def revert_series_if_last(key, name):
prefix = key
if '.' in prefix:
prefix = parse_naming_series(prefix.split('.'))
prefix = parse_naming_series(prefix.split('.'), doc=doc)
count = cint(name.replace(prefix, ""))
current = frappe.db.sql("SELECT `current` FROM `tabSeries` WHERE `name`=%s FOR UPDATE", (prefix,))