[FIX] Remove the select for update and use a lock table
lp bug: https://launchpad.net/bugs/314449 fixed bzr revid: stephane@tinyerp.com-20090129161022-6zr4k03d7qil2342
This commit is contained in:
parent
55ab099cb9
commit
f31ce5813b
|
@ -70,14 +70,18 @@ class ir_sequence(osv.osv):
|
|||
}
|
||||
|
||||
def get_id(self, cr, uid, sequence_id, test='id=%s', context={}):
|
||||
cr.execute('select id,number_next,number_increment,prefix,suffix,padding from ir_sequence where '+test+' and active=True FOR UPDATE', (sequence_id,))
|
||||
res = cr.dictfetchone()
|
||||
if res:
|
||||
cr.execute('update ir_sequence set number_next=number_next+number_increment where id=%s and active=True', (res['id'],))
|
||||
if res['number_next']:
|
||||
return self._process(res['prefix']) + '%%0%sd' % res['padding'] % res['number_next'] + self._process(res['suffix'])
|
||||
else:
|
||||
return self._process(res['prefix']) + self._process(res['suffix'])
|
||||
try:
|
||||
cr.execute('lock table ir_sequence')
|
||||
cr.execute('select id,number_next,number_increment,prefix,suffix,padding from ir_sequence where '+test+' and active=True', (sequence_id,))
|
||||
res = cr.dictfetchone()
|
||||
if res:
|
||||
cr.execute('update ir_sequence set number_next=number_next+number_increment where id=%s and active=True', (res['id'],))
|
||||
if res['number_next']:
|
||||
return self._process(res['prefix']) + '%%0%sd' % res['padding'] % res['number_next'] + self._process(res['suffix'])
|
||||
else:
|
||||
return self._process(res['prefix']) + self._process(res['suffix'])
|
||||
finally:
|
||||
cr.commit()
|
||||
return False
|
||||
|
||||
def get(self, cr, uid, code):
|
||||
|
|
Loading…
Reference in New Issue