[MERGE] lp:923884 (account: fix generation of journal codes to avoid infinite loop)

bzr revid: rco@openerp.com-20120203084622-b3vctd1djh8itkjd
This commit is contained in:
Raphael Collet 2012-02-03 09:46:22 +01:00
commit e33ce2e84a
1 changed files with 5 additions and 4 deletions

View File

@ -3356,13 +3356,14 @@ class wizard_multi_charts_accounts(osv.osv_memory):
# because we can't rely on the value current_num as,
# its possible that we already have bank journals created (e.g. by the creation of res.partner.bank)
# and the next number for account code might have been already used before for journal
journal_count = 0
while True:
journal_code = _('BNK') + str(current_num + journal_count)
for num in xrange(current_num, 100):
# journal_code has a maximal size of 5, hence we can enforce the boundary num < 100
journal_code = _('BNK')[:3] + str(num)
ids = obj_journal.search(cr, uid, [('code', '=', journal_code), ('company_id', '=', company_id)], context=context)
if not ids:
break
journal_count += 1
else:
raise osv.except_osv(_('Error'), _('Cannot generate an unused journal code.'))
vals = {
'name': line['acc_name'],