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 8723)
+++ main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_browser.py	(revision 8753)
@@ -194,8 +194,15 @@
         self.browser.getControl("Add online payment ticket").click()
         self.browser.getControl("Create ticket").click()
+        self.assertMatches('...Wrong state...',
+                           self.browser.contents)
+        IWorkflowState(self.student).setState('cleared')
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl("Create ticket").click()
         self.assertMatches('...Amount could not be determined...',
                            self.browser.contents)
-        IWorkflowState(self.student).setState('cleared')
-        self.browser.open(self.payments_path + '/addop')
+
+        self.app['configuration']['2004'].school_fee_base = 6666.0
+
+        self.browser.getControl("Add online payment ticket").click()
         self.browser.getControl("Create ticket").click()
         self.assertMatches('...ticket created...',
@@ -217,4 +224,32 @@
         self.assertMatches('...This type of payment has already been made...',
                            self.browser.contents)
+        self.browser.open(self.payments_path + '/addop')
+        # Also the other payments can be made
+        self.browser.getControl(name="form.p_category").value = ['gown']
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...ticket created...',
+                           self.browser.contents)
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl(name="form.p_category").value = ['transfer']
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...ticket created...',
+                           self.browser.contents)
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl(
+            name="form.p_category").value = ['bed_allocation']
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...ticket created...',
+                           self.browser.contents)
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl(
+            name="form.p_category").value = ['hostel_maintenance']
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...ticket created...',
+                           self.browser.contents)
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl(name="form.p_category").value = ['clearance']
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...ticket created...',
+                           self.browser.contents)
         # Remove all payments so that we can add a school fee payment again
         keys = [i for i in self.student['payments'].keys()]
@@ -222,53 +257,41 @@
             del self.student['payments'][payment]
         self.browser.open(self.payments_path + '/addop')
-        self.browser.getControl("Create ticket").click()
-        self.assertMatches('...ticket created...',
-                           self.browser.contents)
-        self.browser.open(self.payments_path + '/addop')
-        self.browser.getControl(name="form.p_category").value = ['gown']
-        self.browser.getControl("Create ticket").click()
-        self.assertMatches('...ticket created...',
-                           self.browser.contents)
-        self.browser.open(self.payments_path + '/addop')
-        self.browser.getControl(name="form.p_category").value = ['transfer']
-        self.browser.getControl("Create ticket").click()
-        self.assertMatches('...ticket created...',
-                           self.browser.contents)
-        self.browser.open(self.payments_path + '/addop')
-        self.browser.getControl(
-            name="form.p_category").value = ['bed_allocation']
-        self.browser.getControl("Create ticket").click()
-        self.assertMatches('...ticket created...',
-                           self.browser.contents)
-        self.browser.open(self.payments_path + '/addop')
-        self.browser.getControl(
-            name="form.p_category").value = ['hostel_maintenance']
-        self.browser.getControl("Create ticket").click()
-        self.assertMatches('...ticket created...',
-                           self.browser.contents)
-        self.browser.open(self.payments_path + '/addop')
-        self.browser.getControl(name="form.p_category").value = ['clearance']
-        self.browser.getControl("Create ticket").click()
-        self.assertMatches('...ticket created...',
-                           self.browser.contents)
-        self.browser.open(self.payments_path + '/addop')
-        self.browser.getControl(name="form.p_category").value = ['schoolfee']
-        self.browser.getControl("Create ticket").click()
-        self.assertMatches('...ticket created...',
-                           self.browser.contents)
-        # In state returning we can add a new school fee ticket since
-        # p_session and p_level is different
+        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...ticket created...',
+                           self.browser.contents)
+        # In state returning we can't add a new school fee ticket 
+        # for the next session because the second instalment is missing ...
         IWorkflowState(self.student).setState('returning')
         self.browser.open(self.payments_path + '/addop')
-        self.browser.getControl(name="form.p_category").value = ['schoolfee']
-        self.browser.getControl("Create ticket").click()
-        self.assertMatches('...ticket created...',
-                           self.browser.contents)
-        # In state admitted school fee can't be determined
-        IWorkflowState(self.student).setState('admitted')
-        self.browser.open(self.payments_path + '/addop')
-        self.browser.getControl(name="form.p_category").value = ['schoolfee']
-        self.browser.getControl("Create ticket").click()
-        self.assertMatches('...Amount could not be determined...',
+        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...2nd school fee instalment has not yet been paid...',
+                           self.browser.contents)
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
+        # ... and the first one has not yet been approved.
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...1st school fee instalment has not yet been paid...',
+                           self.browser.contents)
+        # Ok, then we approve the first instalment ...
+        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.assertMatches('...ticket created...',
+                           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')
+        # ... and finally add the 1st instalment for the next session.
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...ticket created...',
                            self.browser.contents)
 
@@ -324,15 +347,17 @@
         self.app['configuration']['2004'].booking_fee = 150.0
         self.app['configuration']['2004'].maint_fee = 180.0
+        self.app['configuration']['2004'].clearance_fee = 1234.0
+        self.app['configuration']['2004'].school_fee_base = 6666.0
         utils = getUtility(IStudentsUtils)
 
-        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
         self.assertEqual(payment, None)
-        self.assertEqual(error, u'Amount could not be determined.')
+        self.assertEqual(error, u'Wrong state.')
 
         IWorkflowState(self.student).setState('cleared')
-        error, payment = utils.setPaymentDetails('schoolfee',self.student)
-        self.assertEqual(payment.p_level, 100)
-        self.assertEqual(payment.p_session, 2004)
-        self.assertEqual(payment.amount_auth, 40000.0)
+        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
+        self.assertEqual(payment.p_level, 100)
+        self.assertEqual(payment.p_session, 2004)
+        self.assertEqual(payment.amount_auth, 6666.0)
         self.assertEqual(payment.p_item, u'CERT1')
         self.assertEqual(error, None)
@@ -340,12 +365,12 @@
         # Add penalty fee.
         self.app['configuration']['2004'].penalty_ug = 99.0
-        error, payment = utils.setPaymentDetails('schoolfee',self.student)
-        self.assertEqual(payment.amount_auth, 40099.0)
+        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
+        self.assertEqual(payment.amount_auth, 6765.0)
 
         IWorkflowState(self.student).setState('returning')
-        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
         self.assertEqual(payment.p_level, 200)
         self.assertEqual(payment.p_session, 2005)
-        self.assertEqual(payment.amount_auth, 20099.0)
+        self.assertEqual(payment.amount_auth, 6765.0)
         self.assertEqual(payment.p_item, u'CERT1')
         self.assertEqual(error, None)
@@ -354,5 +379,5 @@
         self.assertEqual(payment.p_level, 100)
         self.assertEqual(payment.p_session, 2004)
-        self.assertEqual(payment.amount_auth, 34250.0)
+        self.assertEqual(payment.amount_auth, 1234.0)
         self.assertEqual(payment.p_item, u'CERT1')
         self.assertEqual(error, None)
