Index: /WAeUP_SRP/trunk/skins/waeup_pins/scratch_card_batch_create_do.py
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_pins/scratch_card_batch_create_do.py	(revision 5178)
+++ /WAeUP_SRP/trunk/skins/waeup_pins/scratch_card_batch_create_do.py	(revision 5179)
@@ -8,21 +8,33 @@
 from Products.CMFCore.utils import getToolByName
 
+#try:
+#    from Products.zdb import set_trace
+#except:
+#    def set_trace():
+#        pass
+
+
 prefix = datamodel.get('prefix').upper()
 datamodel.set('prefix',prefix)
 bl = context.portal_catalog({'meta_type': "ScratchCardBatch",})
 b_ids = []
+
 for b in bl:
     b_ids.append(b.getId)
-next = 1
-while b_ids and "%s_%d" % (prefix,next) in b_ids:
-    next += 1
+
+p_ids = [p_id for p_id in b_ids if p_id.startswith(prefix)]
+if p_ids:
+    max_bno = max([int(bno.split('_')[1]) for bno in p_ids])
+    next = max_bno+1
+else:
+    next = 1 
+
+#next = 1
+#while b_ids and "%s_%d" % (prefix,next) in b_ids:
+#    next += 1
+
 id = "%s_%d" % (prefix,next)
+
 datamodel.set('batch_no',next)
-##language = datamodel.get('Language')
-##if not language:
-##    ts = getToolByName(context, 'translation_service')
-##    language = ts.getSelectedLanguage()
-
-# Datamodel is passed so that flexti can initialize the object.
 new_id = context.invokeFactory(type_name, id, datamodel=datamodel,
                                )
@@ -33,5 +45,3 @@
 ob.getContent().edit(mapping=datamodel)
 
-#context.notifyCPSDocumentCreation(ob=ob) # BBB obsolete in CPS 3.5.0
-
 return ob
