Browse Source

[minor] lock tabSeries during update

version-14
Anand Doshi 11 years ago
parent
commit
bee949af45
1 changed files with 4 additions and 3 deletions
  1. +4
    -3
      webnotes/model/doc.py

+ 4
- 3
webnotes/model/doc.py View File

@@ -587,14 +587,15 @@ def make_autoname(key, doctype=''):

def getseries(key, digits, doctype=''):
# series created ?
current = webnotes.conn.get_value("Series", key, "current")
if current != None:
current = webnotes.conn.sql("select `current` from `tabSeries` where name=%s for update", key)
if current and current[0][0]:
current = current[0][0]
# yes, update it
webnotes.conn.sql("update tabSeries set current = current+1 where name=%s", key)
current = cint(current) + 1
else:
# no, create it
webnotes.conn.sql("insert into tabSeries (name, current) values ('%s', 1)" % key)
webnotes.conn.sql("insert into tabSeries (name, current) values (%s, 1)", key)
current = 1
return ('%0'+str(digits)+'d') % current



Loading…
Cancel
Save