Index: main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_browser.py
===================================================================
--- main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_browser.py	(revision 14238)
+++ main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_browser.py	(revision 14241)
@@ -224,8 +224,12 @@
 
     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_pt'
         self.student['studycourse'].certificate.school_fee_1 = 6666.0
-        self.app['configuration']['2004'].union_fee = 1250.0
-        self.app['configuration']['2004'].welfare_fee = 750.0
+        self.app['configuration']['2015'].union_fee = 1250.0
+        self.app['configuration']['2015'].welfare_fee = 750.0
         self.student.nationality = u'NG'
         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
@@ -239,8 +243,9 @@
         self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
         self.browser.getControl("Create ticket").click()
-        self.assertTrue(
-            'Wrong state. Only students in state \'cleared\' are allowed to pay by instalments'
+        self.assertTrue('You are not allowed to pay by instalments.'
             in self.browser.contents)
         IWorkflowState(self.student).setState('cleared')
+        self.student['studycourse'].entry_session = 2015
+        self.student['studycourse'].current_session = 2015
         self.browser.open(self.payments_path + '/addop')
         self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
@@ -274,4 +279,44 @@
         # (6666-250)/2 + 250
         self.assertEqual(self.student['payments'].values()[1].amount_auth, 3458.0)
+        # The  two payments belong to the same session and level.
+        self.assertEqual(self.student['payments'].values()[0].p_session, 2015)
+        self.assertEqual(self.student['payments'].values()[0].p_level, 100)
+        self.assertEqual(self.student['payments'].values()[1].p_session, 2015)
+        self.assertEqual(self.student['payments'].values()[1].p_level, 100)
+
+        # Returning student
+        configuration_2 = createObject('waeup.SessionConfiguration')
+        configuration_2.academic_session = 2016
+        self.app['configuration'].addSessionConfiguration(configuration_2)
+        self.student['studycourse'].certificate.school_fee_2 = 5666.0
+        self.app['configuration']['2016'].union_fee = 1250.0
+        self.app['configuration']['2016'].welfare_fee = 750.0
+        self.student.father_name = u'Albert'
+        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()
+        # Student is still in the first  session.
+        self.assertTrue('This type of payment' in self.browser.contents)
+        self.browser.open(self.payments_path)
+        ctrl = self.browser.getControl(name='val_id')
+        p_id = ctrl.options[2]
+        self.browser.open(self.payments_path + '/' + p_id + '/approve')
+        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)
+        # (5666-250)/2 + 1250 + 750 - 500 + 250
+        self.assertEqual(self.student['payments'].values()[2].amount_auth, 4458.0)
+        # (5666-250)/2 + 250
+        self.assertEqual(self.student['payments'].values()[3].amount_auth, 2958.0)
+        # The last two payments belong to the same session and level.
+        self.assertEqual(self.student['payments'].values()[2].p_session, 2016)
+        self.assertEqual(self.student['payments'].values()[2].p_level, 200)
+        self.assertEqual(self.student['payments'].values()[3].p_session, 2016)
+        self.assertEqual(self.student['payments'].values()[3].p_level, 200)
         return
 
@@ -711,4 +756,5 @@
     def test_student_2nd_semester_course_registration(self):
         IWorkflowState(self.student).setState('school fee paid')
+        self.student['studycourse'].entry_session = 2015
         self.course.semester = 2
         self.browser.open(self.login_path)
