Review: Needs Fixing

This can still loop forever!  Please use a for loop with an else statement, 
something like:

    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)
        journal_ids = journal_obj.search(...)
        if not journal_ids:
            break
    else:
        raise osv.except_osv(_('Error'), _('Cannot generate an unused journal 
code.'))

The for loop is finite, because num never goes beyond 99.  The value is chosen 
on purpose: no code longer than that will ever match, since journal codes have 
size=5 in their field definition.  If a journal code is available, you exit the 
loop without executing the 'else' part.  Otherwise, the exception is raised.

Thanks,
Raphael
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-923884-mdi/+merge/91217
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-923884-mdi.

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to