Index: WAeUP_SRP/base/Payment.py
===================================================================
--- WAeUP_SRP/base/Payment.py	(revision 2895)
+++ WAeUP_SRP/base/Payment.py	(revision 2897)
@@ -31,4 +31,5 @@
         return "Payments"
 
+
     security.declareProtected(View,"updatePayments")
     def updatePayments(self):
@@ -36,51 +37,7 @@
         logger = logging.getLogger('PaymentsFolder.updatePayments')
         #import pdb;pdb.set_trace()
-        wftool = self.portal_workflow
         for payment in self.aq_parent.objectValues():
-            d = {}
-            student_record = self.students_catalog.getRecordByKey(self.getStudentId())
-            doc = payment.getContent()
-            d['key'] = payment.getId()
-            d['amount'] = doc.amount
-            d['type_description'] = doc.type_description
-            subject = ''
-            if doc.type_description.startswith('School'):
-                subject = 'schoolfee'
-            sp = doc.type_description.rfind('/')
-            d['session_id'] = doc.type_description[sp-2:sp]
-            d['subject'] = subject # zb. schoolfee
-            while True:
-                if doc.resp_code == "SC":
-                    p_type = "sc"
-                    p_status = "paid"
-                    break
-                if doc.resp_code in ("00","IP","AP"):
-                    p_type = "online"
-                    p_status = "paid"
-                    break
-                p_type = "online"
-                p_status = "open"
-                break
-            d['key'] = payment.getId()
-            d['type'] = p_type  # scratch card
-            d['item'] = student_record.course
-            d['status'] = p_status
-            d['resp_approved_amount'] = getattr(doc,'resp_approved_amount',None)
-            d['resp_pay_reference'] = doc.resp_pay_reference
-            d['resp_desc'] = doc.resp_desc
-            d['order_id'] = doc.order_id
-            d['resp_code'] = doc.resp_code
-            d['resp_card_num'] = doc.resp_card_num
-            d['date'] = getattr(doc,'date',None)
-            #d['resp_date'] = getattr(doc,'resp_date',None)
-            # msg = " ".join(["%s: %s" % (key,value) for key,value in d.items()])
-            # logger.info(msg)
-
-            review_state = wftool.getInfoFor(payment,'review_state',None)
-            if review_state == "closed":
-                wftool.doActionFor(payment,'open')
-            doc.edit(mapping = d)
-            if review_state == "closed":
-                wftool.doActionFor(payment,'close')
+            student_record = self.getRecordByKey(self.getStudentId())
+            payment['updatePayment'](student_record)
 
 InitializeClass(PaymentsFolder)
@@ -114,4 +71,53 @@
     ###)
 
+    security.declareProtected(View,"updatePayment")
+    def updatePayment(self,student_record):
+        doc = self.getContent()
+        if getattr(doc,'status',None):
+            return
+        wftool = self.portal_workflow
+        d = {}
+        #student_record = self.students_catalog.getRecordByKey(self.getStudentId())
+        d['key'] = self.getId()
+        d['amount'] = doc.amount
+        #d['description'] = d['type_description'] = doc.type_description
+        category = ''
+        if doc.type_description.startswith('School'):
+            category = 'schoolfee'
+        sp = doc.type_description.rfind('/')
+        d['session_id'] = doc.type_description[sp-2:sp]
+        d['category'] = category # zb. schoolfee
+        while True:
+            if doc.resp_code == "SC":
+                p_type = "sc"
+                p_status = "paid"
+                break
+            if doc.resp_code in ("00","IP","AP"):
+                p_type = "online"
+                p_status = "paid"
+                break
+            p_type = "online"
+            p_status = "started"
+            break
+        d['type'] = p_type  # scratch card
+        d['item'] = getattr(student_record,'course','')
+        d['status'] = p_status
+        d['resp_approved_amount'] = getattr(doc,'resp_approved_amount',None)
+        d['resp_pay_reference'] = doc.resp_pay_reference
+        d['resp_desc'] = doc.resp_desc
+        d['order_id'] = self.aq_parent.getId()
+        d['resp_code'] = doc.resp_code
+        d['resp_card_num'] = doc.resp_card_num
+        d['date'] = getattr(doc,'date',None)
+        # msg = " ".join(["%s: %s" % (key,value) for key,value in d.items()])
+        # logger.info(msg)
+        
+        review_state = wftool.getInfoFor(self,'review_state',None)
+        if review_state == "closed":
+            wftool.doActionFor(self,'open')
+        doc.edit(mapping = d)
+        if review_state == "closed":
+            wftool.doActionFor(self,'close')
+
 InitializeClass(Payment)
 
Index: WAeUP_SRP/base/WAeUPTables.py
===================================================================
--- WAeUP_SRP/base/WAeUPTables.py	(revision 2895)
+++ WAeUP_SRP/base/WAeUPTables.py	(revision 2897)
@@ -1474,5 +1474,5 @@
         except:
             logger = logging.getLogger('WAeUPTables.PaymentsCatalog.%s' % self.__name__)
-            logger.info("could not add or modify entry for %(key)s" % data)
+            logger.info("could not add or modify entry for %(order_id)s" % data)
     ###)
 
Index: WAeUP_SRP/base/skins/waeup_epayment/upgradePayments.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_epayment/upgradePayments.py	(revision 2895)
+++ WAeUP_SRP/base/skins/waeup_epayment/upgradePayments.py	(revision 2897)
@@ -50,62 +50,21 @@
 logger.info("found %d payments" % total)
 sid = "xxx"
-#set_trace()
 count = 1
 commit_after = 5
 commit_count = 0
 
-set_trace()
+student_id = ''
 for payment_brain in payments:
     payment = payment_brain.getObject()
-    payment['updatePayment']()
-    # student_id = payment.getPath().split('/')[-3]
-    # student_brain = context.students_catalog.getRecordByKey(student_id)
-    # if student_brain is None:
-    #     logger.info("student %s not in students_catalog" % student_id)
-    #     continue
-    # d = {}
-    # doc = payment.getObject().getContent()
-    # d['key'] = payment.getId
-    # d['amount'] = doc.amount
-    # d['description'] = d['type_description'] = doc.type_description
-    # subject = ''
-    # if doc.type_description.startswith('School'):
-    #     subject = 'schoolfee'
-    # sp = doc.type_description.rfind('/')
-    # d['session_id'] = doc.type_description[sp-2:sp]
-    # d['subject'] = subject # zb. schoolfee
-    # d['target'] = "%s" % (student_brain.course)  # faculty departmen course
-    # while True:
-    #     if doc.resp_code == "SC":
-    #         p_type = "sc"
-    #         p_status = "paid"
-    #         break
-    #     if doc.resp_code == "00":
-    #         p_type = "onl"
-    #         p_status = "paid"
-    #         break
-    #     p_type = "ONL"
-    #     p_status = "open"
-    #     break
-    # d['key'] = payment.getId
-    # d['type'] = p_type  # scratch card
-    # d['status'] = p_status
-    # d['resp_approved_amount'] = getattr(doc,'resp_approved_amount',None)
-    # d['resp_pay_reference'] = doc.resp_pay_reference
-    # d['resp_desc'] = doc.resp_desc
-    # d['order_id'] = doc.order_id
-    # d['resp_code'] = doc.resp_code
-    # d['resp_card_num'] = doc.resp_card_num
-    # d['date'] = getattr(doc,'date',None)
-    # d['resp_date'] = getattr(doc,'resp_date',None)
-    # doc.edit(mapping = d)
-    # msg = " ".join(["%s: %s" % (key,value) for key,value in d.items()])
-    # rwrite(msg)
-    logger.info('upgraded student %s payment %s' % (student_id,d['key']))
+    if payment_brain.getPath().split('/')[-3] != student_id:
+        student_id = payment_brain.getPath().split('/')[-3]
+        student_record = context.students_catalog.getRecordByKey(student_id)
+    payment['updatePayment'](student_record)
+    logger.info('upgraded student %s payment %s' % (student_record.id,payment.getId()))
     if not count % commit_after:
         logger.info("committing %d total %d" % (commit_after,count))
         commit_count += 1
-        # if not commit_count % 2:
-        #     break
+        if not commit_count % 2:
+            break
     count += 1
 logger.info("%d of %d upgraded" % (count,total))
