Index: main/waeup.uniben/trunk/src/waeup/uniben/students/interfaces.py
===================================================================
--- main/waeup.uniben/trunk/src/waeup/uniben/students/interfaces.py	(revision 9006)
+++ main/waeup.uniben/trunk/src/waeup/uniben/students/interfaces.py	(revision 9152)
@@ -71,4 +71,10 @@
     """
 
+    p_current = schema.Bool(
+        title = _(u'Current Session Payment'),
+        default = True,
+        required = False,
+        )
+
     p_level = schema.Int(
         title = _(u'Payment Level'),
Index: main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_browser.py
===================================================================
--- main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_browser.py	(revision 9006)
+++ main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_browser.py	(revision 9152)
@@ -221,15 +221,36 @@
         utils = getUtility(IStudentsUtils)
 
+        self.student.nationality = u'NG'
+
         configuration = createObject('waeup.SessionConfiguration')
         configuration.academic_session = 2005
         self.app['configuration'].addSessionConfiguration(configuration)
 
-        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        error, payment = utils.setPaymentDetails('schoolfee',
+            self.student, None, None)
         self.assertEqual(payment, None)
-        self.assertEqual(error, u'Amount could not be determined.')
-
+        self.assertTrue(u'Amount could not be determined.' in error)
+
+        # Previous session payment, fresh and returning
+        # are being distinguished by their entry_level
+        error, payment = utils.setPaymentDetails('schoolfee',
+            self.student, 2004, 300)
+        self.assertEqual(payment.amount_auth, 40000.0)
+        self.assertEqual(payment.p_session, 2004)
+        self.assertEqual(payment.p_level, 300)
+        self.assertFalse(payment.p_current)
+        self.student['studycourse'].entry_session = 2003
+        error, payment = utils.setPaymentDetails('schoolfee',
+            self.student, 2004, 300)
+        self.assertEqual(payment.amount_auth, 20000.0)
+        self.assertEqual(payment.p_session, 2004)
+        self.assertEqual(payment.p_level, 300)
+        self.assertFalse(payment.p_current)
+
+        # Current payment, fresh and returning
+        # are being distinguished by their state
         IWorkflowState(self.student).setState('cleared')
-        self.student.nationality = u'NG'
-        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        error, payment = utils.setPaymentDetails('schoolfee',
+            self.student, None, None)
         self.assertEqual(payment.p_level, 100)
         self.assertEqual(payment.p_session, 2004)
@@ -237,4 +258,5 @@
         self.assertEqual(payment.p_item, u'CERT1')
         self.assertEqual(error, None)
+        self.assertTrue(payment.p_current)
 
         # Add penalty fee ...
@@ -243,9 +265,11 @@
         # ... for returning
         self.app['configuration']['2005'].penalty_ug = 88.0
-        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        error, payment = utils.setPaymentDetails('schoolfee',
+            self.student, None, None)
         self.assertEqual(payment.amount_auth, 40099.0)
 
         IWorkflowState(self.student).setState('returning')
-        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        error, payment = utils.setPaymentDetails('schoolfee',
+            self.student, None, None)
         self.assertEqual(payment.p_level, 200)
         self.assertEqual(payment.p_session, 2005)
@@ -255,5 +279,6 @@
 
         self.student.is_staff = True
-        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        error, payment = utils.setPaymentDetails('schoolfee',
+            self.student, None, None)
         self.assertEqual(payment.p_level, 200)
         self.assertEqual(payment.p_session, 2005)
@@ -266,5 +291,6 @@
         self.student.nationality = u'DE'
         self.certificate.school_fee_3 = 60000.0
-        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        error, payment = utils.setPaymentDetails(
+            'schoolfee', self.student, None, None)
         self.assertEqual(payment.p_level, 100)
         self.assertEqual(payment.p_session, 2004)
@@ -277,5 +303,6 @@
         self.student.nationality = u'DE'
         self.certificate.school_fee_4 = 20000.0
-        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        error, payment = utils.setPaymentDetails(
+            'schoolfee', self.student, None, None)
         self.assertEqual(payment.p_level, 200)
         self.assertEqual(payment.p_session, 2005)
@@ -284,5 +311,6 @@
         self.assertEqual(error, None)
 
-        error, payment = utils.setPaymentDetails('clearance',self.student)
+        error, payment = utils.setPaymentDetails('clearance',
+            self.student, None, None)
         self.assertEqual(payment.p_level, 100)
         self.assertEqual(payment.p_session, 2004)
@@ -291,5 +319,6 @@
         self.assertEqual(error, None)
 
-        error, payment = utils.setPaymentDetails('gown',self.student)
+        error, payment = utils.setPaymentDetails('gown',
+            self.student, None, None)
         self.assertEqual(payment.p_level, 100)
         self.assertEqual(payment.p_session, 2004)
@@ -298,5 +327,6 @@
         self.assertEqual(error, None)
 
-        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
+        error, payment = utils.setPaymentDetails('hostel_maintenance',
+            self.student, None, None)
         self.assertEqual(payment.p_level, 100)
         self.assertEqual(payment.p_session, 2004)
@@ -305,5 +335,6 @@
         self.assertEqual(error, None)
 
-        error, payment = utils.setPaymentDetails('bed_allocation',self.student)
+        error, payment = utils.setPaymentDetails('bed_allocation',
+            self.student, None, None)
         self.assertEqual(payment.p_level, 100)
         self.assertEqual(payment.p_session, 2004)
@@ -312,5 +343,6 @@
         self.assertEqual(error, None)
 
-        error, payment = utils.setPaymentDetails('transfer',self.student)
+        error, payment = utils.setPaymentDetails('transfer',
+            self.student, None, None)
         self.assertEqual(payment.p_level, 100)
         self.assertEqual(payment.p_session, 2004)
Index: main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py
===================================================================
--- main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py	(revision 9006)
+++ main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py	(revision 9152)
@@ -48,5 +48,6 @@
         return new_session, new_level
 
-    def setPaymentDetails(self, category, student):
+    def setPaymentDetails(self, category, student,
+            previous_session, previous_level):
         """Create Payment object and set the payment data of a student for
         the payment category specified.
@@ -57,6 +58,12 @@
         amount = 0.0
         error = u''
-        p_session = student['studycourse'].current_session
-        p_level = student['studycourse'].current_level
+        if previous_session:
+            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
         session = str(p_session)
         try:
@@ -89,41 +96,54 @@
             except (AttributeError, TypeError):
                 return _('Study course data are incomplete.'), None
-            if student.state == CLEARED:
-                if student.is_foreigner:
-                    amount = getattr(certificate, 'school_fee_3', 0.0)
+            if previous_session:
+                if student.current_session == student['studycourse'].entry_session:
+                    if student.is_foreigner:
+                        amount = getattr(certificate, 'school_fee_3', 0.0)
+                    else:
+                        amount = getattr(certificate, 'school_fee_1', 0.0)
                 else:
-                    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.
-                p_session, p_level = self.getReturningData(student)
-                if student.is_foreigner:
-                    amount = getattr(certificate, 'school_fee_4', 0.0)
-                else:
-                    amount = getattr(certificate, 'school_fee_2', 0.0)
-                try:
-                    academic_session = grok.getSite()[
-                        'configuration'][str(p_session)]
-                except KeyError:
-                    return _(u'Session configuration object is not available.'), None
-            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
-                if student.is_foreigner:
-                    amount = getattr(certificate, 'school_fee_4', 0.0)
-                else:
-                    amount = getattr(certificate, 'school_fee_2', 0.0)
-                try:
-                    academic_session = grok.getSite()[
-                        'configuration'][str(p_session)]
-                except KeyError:
-                    return _(u'Session configuration object is not available.'), None
+                    if student.is_foreigner:
+                        amount = getattr(certificate, 'school_fee_4', 0.0)
+                    else:
+                        amount = getattr(certificate, 'school_fee_2', 0.0)
+            else:
+                if student.state == CLEARED:
+                    if student.is_foreigner:
+                        amount = getattr(certificate, 'school_fee_3', 0.0)
+                    else:
+                        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.
+                    p_session, p_level = self.getReturningData(student)
+                    if student.is_foreigner:
+                        amount = getattr(certificate, 'school_fee_4', 0.0)
+                    else:
+                        amount = getattr(certificate, 'school_fee_2', 0.0)
+                    try:
+                        academic_session = grok.getSite()[
+                            'configuration'][str(p_session)]
+                    except KeyError:
+                        return _(u'Session configuration object is not available.'), None
+                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
+                    if student.is_foreigner:
+                        amount = getattr(certificate, 'school_fee_4', 0.0)
+                    else:
+                        amount = getattr(certificate, 'school_fee_2', 0.0)
+                    try:
+                        academic_session = grok.getSite()[
+                            'configuration'][str(p_session)]
+                    except KeyError:
+                        return _(u'Session configuration object is not available.'), None
             # Give 50% school fee discount to staff members.
             if student.is_staff:
                 amount /= 2
         if amount in (0.0, None):
-            return _(u'Amount could not be determined.'), None
+            return _('Amount could not be determined.' +
+                     ' Would you like to pay for a previous session?'), None
         # Add session specific penalty fee.
         if category == 'schoolfee' and student.is_postgrad:
@@ -138,5 +158,6 @@
                ticket.p_item == p_item and \
                ticket.p_session == p_session:
-                  return _('This type of payment has already been made.'), None
+                  return _('This type of payment has already been made.' +
+                           ' Would you like to pay for a previous session?'), None
         payment = createObject(u'waeup.StudentOnlinePayment')
         timestamp = ("%d" % int(time()*10000))[1:]
@@ -146,4 +167,5 @@
         payment.p_session = p_session
         payment.p_level = p_level
+        payment.p_current = p_current
         payment.amount_auth = amount
         return None, payment
