From f31ce5813ba28150d2f9affc72311626a4ff94b0 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Thu, 29 Jan 2009 17:10:22 +0100 Subject: [PATCH] [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 --- bin/addons/base/ir/ir_sequence.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/bin/addons/base/ir/ir_sequence.py b/bin/addons/base/ir/ir_sequence.py index 31828569d6c..202aac754d2 100644 --- a/bin/addons/base/ir/ir_sequence.py +++ b/bin/addons/base/ir/ir_sequence.py @@ -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):