Index: main/waeup.aaua/trunk/src/waeup/aaua/students/tests/test_browser.py
===================================================================
--- main/waeup.aaua/trunk/src/waeup/aaua/students/tests/test_browser.py	(revision 10172)
+++ main/waeup.aaua/trunk/src/waeup/aaua/students/tests/test_browser.py	(revision 10173)
@@ -119,2 +119,47 @@
         # ... and voila next session registration is allowed
         self.assertTrue(self.student['studycourse'].next_session_allowed)
+
+    def test_set_payment_details(self):
+        self.certificate.school_fee_1 = 100.0
+        self.certificate.school_fee_2 = 200.0
+        utils = getUtility(IStudentsUtils)
+
+        IWorkflowState(self.student).setState('cleared')
+        self.certificate.study_mode = 'ug_ft'
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(payment.p_level, 100)
+        self.assertEqual(payment.p_session, 2004)
+        self.assertEqual(payment.amount_auth, 100.0)
+        self.assertEqual(payment.p_item, u'CERT1')
+        self.assertEqual(error, None)
+
+        IWorkflowState(self.student).setState('returning')
+        configuration = createObject('waeup.SessionConfiguration')
+        configuration.academic_session = 2005
+        self.app['configuration'].addSessionConfiguration(configuration)
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(payment.p_level, 200)
+        self.assertEqual(payment.p_session, 2005)
+        self.assertEqual(payment.amount_auth, 200.0)
+        self.assertEqual(payment.p_item, u'CERT1')
+        self.assertEqual(error, None)
+
+        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
+        self.assertEqual(error, u'Payment by instalments not allowed.')
+        self.certificate.ratio = 0.0
+        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
+        self.assertEqual(error, u'Payment by instalments not allowed.')
+        error, payment = utils.setPaymentDetails('schoolfee_2',self.student)
+        self.assertEqual(error, u'Payment by instalments not allowed.')
+        self.certificate.ratio = 0.4
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(error, u'Payment by instalments required.')
+        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
+        self.assertEqual(payment.amount_auth, 80.0)
+        error, payment = utils.setPaymentDetails('schoolfee_2',self.student)
+        self.assertEqual(payment.amount_auth, 120.0)
+        IWorkflowState(self.student).setState('cleared')
+        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
+        self.assertEqual(payment.amount_auth, 40.0)
+        error, payment = utils.setPaymentDetails('schoolfee_2',self.student)
+        self.assertEqual(payment.amount_auth, 60.0)
Index: main/waeup.aaua/trunk/src/waeup/aaua/students/utils.py
===================================================================
--- main/waeup.aaua/trunk/src/waeup/aaua/students/utils.py	(revision 10172)
+++ main/waeup.aaua/trunk/src/waeup/aaua/students/utils.py	(revision 10173)
@@ -34,5 +34,5 @@
 
     def setPaymentDetails(self, category, student,
-            previous_session, previous_level):
+            previous_session=None, previous_level=None):
         """Create Payment object and set the payment data of a student for
         the payment category specified.
@@ -42,26 +42,13 @@
         amount = 0.0
         if previous_session:
-            if previous_session < student['studycourse'].entry_session:
-                return _('The previous session must not fall below '
-                         'your entry session.'), None
-            if category == 'schoolfee':
-                # School fee is always paid for the following session
-                if previous_session > student['studycourse'].current_session:
-                    return _('This is not a previous session.'), None
-            else:
-                if previous_session > student['studycourse'].current_session - 1:
-                    return _('This is not a previous session.'), None
-            p_session = previous_session
-            p_level = previous_level
-            p_current = False
-        else:
-            p_session = student['studycourse'].current_session
-            p_level = student['studycourse'].current_level
-            p_current = True
+            return _('Previous session payment not yet implemented.'), None
+        p_session = student['studycourse'].current_session
+        p_level = student['studycourse'].current_level
+        p_current = True
         academic_session = self._getSessionConfiguration(p_session)
         if academic_session == None:
             return _(u'Session configuration object is not available.'), None
         # Determine fee.
-        if category == 'schoolfee':
+        if category in ('schoolfee', 'schoolfee_1',  'schoolfee_2'):
             try:
                 certificate = student['studycourse'].certificate
@@ -69,58 +56,51 @@
             except (AttributeError, TypeError):
                 return _('Study course data are incomplete.'), None
-            if previous_session:
-                # Students can pay for previous sessions in all
-                # workflow states.  Fresh students are excluded by the
-                # update method of the PreviousPaymentAddFormPage.
-                if previous_level == 100:
+            ratio = getattr(certificate, 'ratio', 0.0)
+            if ratio is None:
+                ratio = 0.0
+            if category == 'schoolfee' and ratio > 0:
+                return _('Payment by instalments required.'), None
+            if category in ('schoolfee_1',  'schoolfee_2') and ratio == 0:
+                return _('Payment by instalments not allowed.'), None
+            if student.state == CLEARED:
+                if category == 'schoolfee':
                     amount = getattr(certificate, 'school_fee_1', 0.0)
-                else:
+                elif category == 'schoolfee_1':
+                    amount = getattr(certificate, 'school_fee_1', 0.0) * ratio
+                elif category == 'schoolfee_2':
+                    amount = getattr(certificate, 'school_fee_1', 0.0) * (1- ratio)
+            elif student.state == RETURNING:
+                # In case of returning school fee payment the
+                # payment session and level contain the values of
+                # the session the student has paid for. Payment
+                # session is always next 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
+                if category == 'schoolfee':
                     amount = getattr(certificate, 'school_fee_2', 0.0)
-            else:
-                if student.state == CLEARED:
-                    amount = getattr(certificate, 'school_fee_1', 0.0)
-                elif student.state == RETURNING:
-                    # In case of returning school fee payment the
-                    # payment session and level contain the values of
-                    # the session the student has paid for. Payment
-                    # session is always next 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
+                elif category == 'schoolfee_1':
+                    amount = getattr(certificate, 'school_fee_2', 0.0) * ratio
+                elif category == 'schoolfee_2' and ratio:
+                    amount = getattr(certificate, 'school_fee_2', 0.0) * (1- ratio)
+            elif student.is_postgrad and student.state == PAID:
+                # Returning postgraduate students also pay for the
+                # next session but their level always remains the
+                # same.
+                p_session += 1
+                academic_session = self._getSessionConfiguration(p_session)
+                if academic_session == None:
+                    return _(
+                        u'Session configuration object is not available.'
+                        ), None
+                if category == 'schoolfee':
                     amount = getattr(certificate, 'school_fee_2', 0.0)
-                elif student.is_postgrad and student.state == PAID:
-                    # Returning postgraduate students also pay for the
-                    # next session but their level always remains the
-                    # same.
-                    p_session += 1
-                    academic_session = self._getSessionConfiguration(p_session)
-                    if academic_session == None:
-                        return _(
-                            u'Session configuration object is not available.'
-                            ), None
-                    amount = getattr(certificate, 'school_fee_2', 0.0)
-        elif category == 'clearance':
-            try:
-                p_item = student['studycourse'].certificate.code
-            except (AttributeError, TypeError):
-                return _('Study course data are incomplete.'), None
-            amount = academic_session.clearance_fee
-        elif category == 'bed_allocation':
-            p_item = self.getAccommodationDetails(student)['bt']
-            amount = academic_session.booking_fee
-        elif category == 'hostel_maintenance':
-            amount = academic_session.maint_fee
-            bedticket = student['accommodation'].get(
-                str(student.current_session), None)
-            if bedticket:
-                p_item = bedticket.bed_coordinates
-            else:
-                # Should not happen because this is already checked
-                # in the browser module, but anyway ...
-                portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
-                p_item = trans(_('no bed allocated'), portal_language)
+                elif category == 'schoolfee_1':
+                    amount = getattr(certificate, 'school_fee_2', 0.0) * ratio
+                elif category == 'schoolfee_2' and ratio:
+                    amount = getattr(certificate, 'school_fee_2', 0.0) * (1- ratio)
         if amount in (0.0, None):
             return _('Amount could not be determined.'), None
