Index: main/waeup.kofa/trunk/src/waeup/kofa/students/export.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/export.py	(revision 15059)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/export.py	(revision 15060)
@@ -590,27 +590,56 @@
     """The Session Payments Overview Exporter first filters the set of students
     by searching the students catalog. Then it exports some student base data
-    together with lists of payment years for a predefined range of payment
-    categories.
+    together with the total amount paid in predefined payment categories
+    over the previous three session (referring to current academic session).
+    Sample output:
+
+    header: ``...schoolfee13,schoolfee14,schoolfee15,gown13,gown14,gown15...``
+
+    data: ``...2000.0,,3000.0,,,1000.0,...``
+
+    This csv data string means that the student paid 2000 school fee in 2013
+    3000 in 2015. She furthermore paid 1000 for gown rental in 2015.
     """
     grok.name('sessionpaymentsoverview')
 
     paycats = ('schoolfee', 'clearance', 'gown', 'transcript')
-    fields = ('student_id', 'matric_number', 'display_fullname',
+    regular_fields = ('student_id', 'matric_number', 'display_fullname',
         'state', 'certcode', 'faccode', 'depcode', 'is_postgrad',
         'current_level', 'current_session', 'current_mode',
         'entry_session', 'reg_number'
-        ) + paycats
+        )
     title = _(u'Session Payments Overview')
 
-    def mangle_value(self, value, name, context=None):
-        """
-        """
-        if name in self.paycats and context is not None:
-            value = ''
+    @property
+    def paycatyears(self):
+        cas = grok.getSite()['configuration'].current_academic_session
+        paycatyears = []
+        if cas:
+            year_range = range(cas - 2, cas+1)
+            year_range_tuple = tuple([str(year)[2:] for year in year_range])
+            paycatyears = [
+                cat+year for cat in self.paycats for year in year_range_tuple]
+        return paycatyears
+
+    @property
+    def fields(self):
+        return self.regular_fields + tuple(self.paycatyears)
+
+    def mangle_value(self, value, name, context=None):
+        """
+        """
+        amounts = dict()
+        for catyear in self.paycatyears:
+            amounts[catyear] = 0.0
+        if name[:-2] in self.paycats and context is not None:
             for ticket in context['payments'].values():
-                if ticket.p_category == name:
+                if ticket.p_category == name[:-2]:
                     if ticket.p_state in ('waived', 'paid'):
-                        value += '%s ' % ticket.p_session
-            value = value.strip().replace(' ', '+')
+                        if str(ticket.p_session)[2:] == name[-2:]:
+                            amounts[name] += ticket.amount_auth
+            if amounts[name] == 0.0:
+                value = ''
+            elif isinstance(amounts[name], float):
+                value = round(amounts[name], 2)
         return super(
             StudentExporter, self).mangle_value(
Index: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py	(revision 15059)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py	(revision 15060)
@@ -1239,4 +1239,5 @@
         super(SessionPaymentsOverviewExporterTest, self).setUp()
         self.setup_for_export()
+        grok.getSite()['configuration'].current_academic_session = curr_year - 4
         return
 
@@ -1262,14 +1263,14 @@
             'student_id,matric_number,display_fullname,state,certcode,'
             'faccode,depcode,is_postgrad,current_level,current_session,'
-            'current_mode,entry_session,reg_number,schoolfee,clearance,'
-            'gown,transcript\r\n'
-            'A111111,234,Anna M. Tester,created,CERT1,NA,NA,0,200,2012,'
-            'ug_ft,2010,123,2012,,,' in result
+            'current_mode,entry_session,reg_number,schoolfee12,'
+            'schoolfee13,schoolfee14,clearance12,clearance13,clearance14,'
+            'gown12,gown13,gown14,transcript12,transcript13,transcript14\r\n'
+            'A111111,234,Anna M. Tester,created,CERT1,NA,NA,0,200,'
+            '2012,ug_ft,2010,123,'
+            '12.12,,,,,,,,,,,\r\n' in result
             )
         return
 
     def test_export_all(self):
-        # we can really export students
-        # set values we can expect in export file
         self.setup_student(self.student)
         # We add successful payments.
@@ -1302,9 +1303,14 @@
         result = open(self.outfile, 'rb').read()
         self.assertTrue(
-            'student_id,matric_number,display_fullname,state,certcode,'
-            'faccode,depcode,is_postgrad,current_level,current_session,'
-            'current_mode,entry_session,reg_number,schoolfee,clearance,'
-            'gown,transcript\r\nA111111,234,Anna M. Tester,created,CERT1,'
-            'NA,NA,0,200,2012,ug_ft,2010,123,2013+2013+2014+2012,,,\r\n'
+            'student_id,matric_number,display_fullname,state,certcode,faccode,'
+            'depcode,is_postgrad,current_level,current_session,'
+            'current_mode,entry_session,reg_number,'
+            'schoolfee12,schoolfee13,schoolfee14,'
+            'clearance12,clearance13,clearance14,'
+            'gown12,gown13,gown14,'
+            'transcript12,transcript13,transcript14\r\n'
+            'A111111,234,Anna M. Tester,created,CERT1,NA,NA,0,200,2012,ug_ft,'
+            '2010,123,'
+            '12.12,14.14,1.01,,,,,,,,,\r\n'
             in result
             )
