Index: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/students/tests/test_utils.py
===================================================================
--- main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/students/tests/test_utils.py	(revision 16127)
+++ main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/students/tests/test_utils.py	(revision 16136)
@@ -39,2 +39,76 @@
         self.assertEqual(msg, None)
         return
+
+    def test_set_payment_details(self):
+        self.app['configuration']['2004'].book = 150.0
+        self.app['configuration']['2004'].develop = 90.0
+        self.app['configuration']['2004'].registration = 180.0
+        self.app['configuration']['2004'].municipal_fresh = 280.0
+        self.app['configuration']['2004'].pcf = 380.0
+        self.student['studycourse'].certificate.school_fee_2 = 6666.0
+        IWorkflowState(self.student).setState('cleared')
+        utils = getUtility(IStudentsUtils)
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(error,
+            'Registration Fee, Book Deposit, Development Fee, Municipal Fee, '
+            'Parents Consultative Forum (PCF) Fee must be paid before Tution Fee.')
+        reg_payment = createObject('waeup.StudentOnlinePayment')
+        reg_payment.p_category = u'registration'
+        reg_payment.p_id = u'anyid'
+        reg_payment.p_state = u'paid'
+        reg_payment.p_session = 2004
+        self.student['payments']['anykey'] = reg_payment
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(error,
+            'Book Deposit, Development Fee, Municipal Fee, Parents Consultative '
+            'Forum (PCF) Fee must be paid before Tution Fee.')
+        IWorkflowState(self.student).setState('returning')
+        configuration = createObject('waeup.SessionConfiguration')
+        configuration.academic_session = 2005
+        self.app['configuration'].addSessionConfiguration(configuration)
+        self.app['configuration']['2005'].registration = 170.0
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(error,
+            'Registration Fee, Book Deposit, Development Fee, Municipal Fee, '
+            'Parents Consultative Forum (PCF) Fee must be paid before Tution Fee.')
+        reg_payment.p_session = 2005
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(error,
+            'Book Deposit, Development Fee, Municipal Fee, Parents Consultative '
+            'Forum (PCF) Fee must be paid before Tution Fee.')
+        pcf_payment = createObject('waeup.StudentOnlinePayment')
+        pcf_payment.p_category = u'parentsconsult'
+        pcf_payment.p_id = u'anyid'
+        pcf_payment.p_state = u'paid'
+        pcf_payment.p_session = 2005
+        self.student['payments']['anykey2'] = pcf_payment
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(error,
+            'Book Deposit, Development Fee, Municipal Fee must be paid before Tution Fee.')
+        munic_payment = createObject('waeup.StudentOnlinePayment')
+        munic_payment.p_category = u'municipal_fresh'
+        munic_payment.p_id = u'anyid'
+        munic_payment.p_state = u'paid'
+        munic_payment.p_session = 2005
+        self.student['payments']['anykey3'] = munic_payment
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(error,
+            'Book Deposit, Development Fee must be paid before Tution Fee.')
+        book_payment = createObject('waeup.StudentOnlinePayment')
+        book_payment.p_category = u'book'
+        book_payment.p_id = u'anyid'
+        book_payment.p_state = u'paid'
+        book_payment.p_session = 2005
+        self.student['payments']['anykey4'] = book_payment
+        develop_payment = createObject('waeup.StudentOnlinePayment')
+        develop_payment.p_category = u'develop'
+        develop_payment.p_id = u'anyid'
+        develop_payment.p_state = u'paid'
+        develop_payment.p_session = 2005
+        self.student['payments']['anykey5'] = develop_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)
+        return
