Index: main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/tests/test_browser.py
===================================================================
--- main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/tests/test_browser.py	(revision 14336)
+++ main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/tests/test_browser.py	(revision 14344)
@@ -42,4 +42,72 @@
     layer = FunctionalLayer
 
-    def test_dummytest(self):
+    def test_for_instalment_payments(self):
+
+        #configuration_1 = createObject('waeup.SessionConfiguration')
+        #configuration_1.academic_session = 2015
+        #self.app['configuration'].addSessionConfiguration(configuration_1)
+        self.student['studycourse'].certificate.study_mode = 'ug_ft'
+        self.student.nationality = u'NG'
+        # Fresh student
+        IWorkflowState(self.student).setState('cleared')
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.open(self.payments_path + '/addop')
+        # Add first instalment
+        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
+        self.browser.getControl("Create ticket").click()
+        self.assertTrue('ticket created' in self.browser.contents)
+        self.browser.open(self.payments_path)
+        ctrl = self.browser.getControl(name='val_id')
+        p_id = ctrl.options[0]
+        self.browser.open(self.payments_path + '/' + p_id + '/approve')
+        # Add the second instalment ...
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
+        self.browser.getControl("Create ticket").click()
+        self.assertTrue('ticket created' in self.browser.contents)
+        # ... approve the second instalment ...
+        ctrl = self.browser.getControl(name='val_id')
+        p_id = ctrl.options[1]
+        self.browser.open(self.payments_path + '/' + p_id + '/approve')
+        self.assertEqual(self.student['payments'].values()[0].p_category, 'schoolfee_1')
+        self.assertEqual(self.student['payments'].values()[1].p_category, 'schoolfee_2')
+        # 79200 / 2 + 300
+        self.assertEqual(self.student['payments'].values()[0].amount_auth, 39900.0)
+        self.assertEqual(self.student['payments'].values()[1].amount_auth, 39900.0)
+        # The  two payments belong to the same session and level.
+        self.assertEqual(self.student['payments'].values()[0].p_session, 2004)
+        self.assertEqual(self.student['payments'].values()[0].p_level, 100)
+        self.assertEqual(self.student['payments'].values()[1].p_session, 2004)
+        self.assertEqual(self.student['payments'].values()[1].p_level, 100)
+
+        # Returning student
+        configuration_2 = createObject('waeup.SessionConfiguration')
+        configuration_2.academic_session = 2005
+        self.app['configuration'].addSessionConfiguration(configuration_2)
+        IWorkflowState(self.student).setState('returning')
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
+        self.browser.getControl("Create ticket").click()
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
+        self.browser.getControl("Create ticket").click()
+        self.browser.open(self.payments_path)
+        ctrl = self.browser.getControl(name='val_id')
+        # Nothing happens if we approve the 2nd instalment for session 2005
+        self.browser.open(self.payments_path + '/' + ctrl.options[3] + '/approve')
+        self.assertEqual(self.student.state, 'returning')
+        # Workflow transition is trigered if we approve the 1st indtalment
+        self.browser.open(self.payments_path + '/' + ctrl.options[2] + '/approve')
+        self.assertEqual(self.student.state, 'school fee paid')
+        self.assertEqual(self.student.current_level, 200)
+        self.assertEqual(self.student.current_session, 2005)
+        # 63100 / 2 + 300
+        self.assertEqual(self.student['payments'].values()[2].amount_auth, 31850.0)
+        self.assertEqual(self.student['payments'].values()[3].amount_auth, 31850.0)
+        # The last two payments belong to the same session and level.
+        self.assertEqual(self.student['payments'].values()[2].p_session, 2005)
+        self.assertEqual(self.student['payments'].values()[2].p_level, 200)
+        self.assertEqual(self.student['payments'].values()[3].p_session, 2005)
+        self.assertEqual(self.student['payments'].values()[3].p_level, 200)
         return
Index: main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/tests/test_utils.py
===================================================================
--- main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/tests/test_utils.py	(revision 14336)
+++ main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/tests/test_utils.py	(revision 14344)
@@ -27,12 +27,22 @@
         self.app['configuration']['2016'].clearance_fee = 10234.0
 
-        error, payment = utils.setPaymentDetails('schoolfee', self.student)
-        self.assertEqual(payment, None)
-        self.assertEqual(error, u'Amount could not be determined.')
-        IWorkflowState(self.student).setState('cleared')
         error, payment = utils.setPaymentDetails('schoolfee',self.student)
         self.assertEqual(payment.p_level, 100)
         self.assertEqual(payment.p_session, 2016)
         self.assertEqual(payment.amount_auth, 79500.0)
+        self.assertEqual(payment.p_item, u'CERT1')
+        self.assertEqual(error, None)
+
+        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
+        self.assertEqual(payment.p_level, 100)
+        self.assertEqual(payment.p_session, 2016)
+        self.assertEqual(payment.amount_auth, 39900.0)
+        self.assertEqual(payment.p_item, u'CERT1')
+        self.assertEqual(error, None)
+
+        error, payment = utils.setPaymentDetails('schoolfee_2',self.student)
+        self.assertEqual(payment.p_level, 100)
+        self.assertEqual(payment.p_session, 2016)
+        self.assertEqual(payment.amount_auth, 39900.0)
         self.assertEqual(payment.p_item, u'CERT1')
         self.assertEqual(error, None)
