Index: main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/students/tests/test_utils.py
===================================================================
--- main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/students/tests/test_utils.py	(revision 15344)
+++ main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/students/tests/test_utils.py	(revision 15361)
@@ -58,2 +58,43 @@
         self.assertEqual(msg, None)
         return
+
+    def test_set_payment_details(self):
+        self.student['studycourse'].certificate.school_fee_1 = 6666.0
+        self.student['studycourse'].certificate.study_mode = 'nd_pt'
+        IWorkflowState(self.student).setState('returning')
+        #self.student.nationality = u'NG'
+        #self.student.lga = 'ebonyi_ukaba'
+        utils = getUtility(IStudentsUtils)
+        configuration = createObject('waeup.SessionConfiguration')
+        configuration.academic_session = 2005
+        self.app['configuration'].addSessionConfiguration(configuration)
+        self.app['configuration']['2004'].ict_entre_fee = 170.0
+        self.app['configuration']['2005'].ict_entre_fee = 180.0
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(error, u'Pay ICT fee(s) first.')
+        error, payment = utils.setPaymentDetails('ict_entre',self.student)
+        self.assertEqual(error, None)
+        self.assertEqual(payment.p_level, 200)
+        self.assertEqual(payment.p_session, 2005)
+        self.assertEqual(payment.amount_auth, 180.0)
+        payment.p_state = 'paid'
+        self.student['payments']['any_key'] = payment
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(error, None)
+        self.assertEqual(payment.p_level, 200)
+        self.assertEqual(payment.p_session, 2005)
+        self.assertEqual(payment.amount_auth, 6666.0)
+
+        IWorkflowState(self.student).setState('cleared')
+        error, payment = utils.setPaymentDetails('ict_entre',self.student)
+        self.assertEqual(error, None)
+        self.assertEqual(payment.p_level, 100)
+        self.assertEqual(payment.p_session, 2004)
+        self.assertEqual(payment.amount_auth, 170.0)
+        payment.p_state = 'paid'
+        self.student['payments']['any_key_2'] = payment
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(error, None)
+        self.assertEqual(payment.p_level, 100)
+        self.assertEqual(payment.p_session, 2004)
+        self.assertEqual(payment.amount_auth, 6666.0)
Index: main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/students/utils.py
===================================================================
--- main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/students/utils.py	(revision 15344)
+++ main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/students/utils.py	(revision 15361)
@@ -92,19 +92,19 @@
         req_payments = ('ict_entre', 'logbook_combo')
         req_payments_titles = 'ICT and Logbook'
+        # All ND and HND part time do not pay for LOGBOOK
+        if student.current_mode.endswith('_pt'):
+            req_payments = ('ict_entre',)
+            req_payments_titles = 'ICT'
+        # HND1 and HND2 full time do not pay for LOGBOOK
+        elif student.current_mode == 'hnd_ft' and student.state in (
+            CLEARED, RETURNING):
+            req_payments = ('ict_entre',)
+            req_payments_titles = 'ICT'
+        # ND2 FULL TIME do not pay LOGBOOK
+        elif student.current_mode == 'nd_ft' and student.state == RETURNING:
+            req_payments = ('ict_entre',)
+            req_payments_titles = 'ICT'
+        num = 0
         if len(student['payments']):
-            # All ND and HND part time do not pay for LOGBOOK
-            if student.current_mode.endswith('_pt'):
-                req_payments = ('ict_entre',)
-                req_payments_titles = 'ICT'
-            # HND1 and HND2 full time do not pay for LOGBOOK
-            elif student.current_mode == 'hnd_ft' and student.state in (
-                CLEARED, RETURNING):
-                req_payments = ('ict_entre',)
-                req_payments_titles = 'ICT'
-            # ND2 FULL TIME do not pay LOGBOOK
-            elif student.current_mode == 'nd_ft' and student.state == RETURNING:
-                req_payments = ('ict_entre',)
-                req_payments_titles = 'ICT'
-            num = 0
             for ticket in student['payments'].values():
                 if ticket.p_state == 'paid' and \
@@ -117,5 +117,5 @@
 
     def setPaymentDetails(self, category, student,
-            previous_session, previous_level):
+            previous_session=None, previous_level=None):
         """Create a payment ticket and set the payment data of a
         student for the payment category specified.
@@ -141,13 +141,13 @@
             p_level = student['studycourse'].current_level
             p_current = True
+        # The following three fees are part of the school fee which must be
+        # paid before tuition fee. They are paid for next session.
+        if category in ('ict_entre', 'logbook_combo', 'siwess_combo') and \
+            student.state == RETURNING and not previous_session:
+            p_session, p_level = self.getReturningData(student)
         academic_session = self._getSessionConfiguration(p_session)
         if academic_session == None:
             return _(u'Session configuration object is not available.'), None
         # Determine fee.
-        # The following three fees are part of the school fee which must be
-        # paid before tuition fee.
-        if category in ('ict_entre', 'logbook_combo', 'siwess_combo') and \
-            student.state == RETURNING and not previous_session:
-            p_session, p_level = self.getReturningData(student)
         if category == 'schoolfee':
             try:
@@ -159,6 +159,8 @@
                 amount = getattr(certificate, 'school_fee_1', 0.0)
             else:
-                amount = getattr(certificate, 'school_fee_1', 0.0)
-                if student.state == RETURNING:
+                if student.state == CLEARED:
+                    amount = getattr(certificate, 'school_fee_1', 0.0)
+                elif student.state == RETURNING:
+                    amount = getattr(certificate, 'school_fee_1', 0.0)
                     # In case of returning school fee payment the
                     # payment session and level contain the values of
@@ -171,9 +173,9 @@
                             u'Session configuration object is not available.'
                             ), None
-                    
                 elif student.is_postgrad and student.state == PAID:
                     # Returning postgraduate students also pay for the
                     # next session but their level always remains the
                     # same.
+                    amount = getattr(certificate, 'school_fee_1', 0.0)
                     p_session += 1
                     academic_session = self._getSessionConfiguration(p_session)
