Index: main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py	(revision 5085)
+++ main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py	(revision 5086)
@@ -27,5 +27,5 @@
     def batch(self):
         return getattr(self, '__parent__', None)
-    
+
     @property
     def batch_prefix(self):
@@ -33,5 +33,5 @@
             return ''
         return self.batch.prefix
-    
+
     @property
     def batch_num(self):
@@ -45,16 +45,15 @@
     grok.implements(IAccessCodeBatch)
 
-    def __init__(self, creation_date, creator, batch_num, batch_prefix, cost,
-                 entry_num):
+    def __init__(self, creation_date, creator, batch_prefix, cost,
+                 entry_num, num=None):
         super(AccessCodeBatch, self).__init__()
         self.creation_date = creation_date
         self.creator = creator
-        self.num = batch_num
         self.prefix = batch_prefix
         self.cost = cost
         self.entry_num = entry_num
-        self._createEntries()
+        self.num = num
 
-    def _createEntries(self):
+    def createEntries(self):
         """Create the entries for this batch.
         """
@@ -65,5 +64,5 @@
             self[str(num)] = ac
         del self._used
-        
+
     def getNewRandomNum(self):
         """Create a random number of 10 digits.
@@ -82,7 +81,22 @@
 
     def addBatch(self, batch):
-        key = "%s_%s" % (batch.prefix, batch.num)
+        """Add a batch.
+        """
+        batch.num = self.getNum(batch.prefix)
+        key = "%s-%s" % (batch.prefix, batch.num)
         self[key] = batch
+        batch.createEntries()
+        self._p_changed = True
+        self.curr_num += 1
 
+    def getNum(self, prefix):
+        """Get next unused num for given prefix.
+        """
+        num = 1
+        prefix = prefix.upper()
+        while self.get('%s-%s' % (prefix, num), None):
+            num += 1
+        return num
+        
 class AccessCodePlugin(grok.GlobalUtility):
     grok.name('accesscodes')
