Index: /main/waeup.kofa/trunk/CHANGES.txt
===================================================================
--- /main/waeup.kofa/trunk/CHANGES.txt	(revision 12970)
+++ /main/waeup.kofa/trunk/CHANGES.txt	(revision 12971)
@@ -4,4 +4,8 @@
 1.3.2.dev0 (unreleased)
 =======================
+
+* Add StudentUnpaidPaymentExporter to export only unpaid tickets.
+  This exporter is designed for finding and finally purging outdated
+  payment ticket.
 
 * Remove deprecated xml importer and exporter components.
Index: /main/waeup.kofa/trunk/docs/source/userdocs/datacenter/export.rst
===================================================================
--- /main/waeup.kofa/trunk/docs/source/userdocs/datacenter/export.rst	(revision 12970)
+++ /main/waeup.kofa/trunk/docs/source/userdocs/datacenter/export.rst	(revision 12971)
@@ -213,4 +213,11 @@
   .. automethod:: waeup.kofa.students.export.StudentPaymentExporter.mangle_value()
 
+Student Unpaid Payment Exporter
+-------------------------------
+
+.. autoclass:: waeup.kofa.students.export.StudentUnpaidPaymentExporter()
+
+  .. autoattribute:: waeup.kofa.students.export.StudentUnpaidPaymentExporter.title
+
 Bed Ticket Exporter
 -------------------
Index: /main/waeup.kofa/trunk/docs/source/userdocs/students.rst
===================================================================
--- /main/waeup.kofa/trunk/docs/source/userdocs/students.rst	(revision 12970)
+++ /main/waeup.kofa/trunk/docs/source/userdocs/students.rst	(revision 12971)
@@ -39,7 +39,9 @@
 The `Student` class is a container class which means, there are not only attributes describing the student but also content. Each student container contains exactly three sub-containers: ``studycourse``  (instance of `StudentStudyCourse`), ``payments`` (instance of `StudentPaymentsContainer`)  ``accommodation`` (instance of `StudentAccommodation`). The purposes of them are described further below.
 
-Let's talk about the attributes and methods belonging to the `Student` class, the so-called 'external behaviour' of student objects. The data stored with each student object are subdivided into three parts: base data, personal data and clearance data.
+Let's talk about the attributes and methods belonging to the `Student` class, the so-called 'external behaviour' of student objects specified in Zope 'interfaces'. The data stored with each student object are subdivided into three parts: base data, personal data and clearance data. Each part has its own interface.
 
-Now comes the point where we have to briefly introduce Zope's (see :ref:`prerequisites`) concept of 'interfaces'. 
+.. note::
+
+  Interfaces are one of the pillars of Zope's Component Architecture (ZCA, see also :ref:`prerequisites`). They document the 'external behaviour' of objects. In Kofa interfaces are used to specify the attributes, methods and schema fields of objects. The first two are well-known Python concepts. A Zope schema field is a bit more complicated. It's a detailed description of a field to be submitted via forms to the server, or which is processed by a batch processor. In both cases the input data are being validated against the schema. In Kofa, schema fields in interfaces are also used to automtically add `FieldProperty` attributes of the same name to most content classes. This is done by a function called :py:func:`attrs_to_fields<waeup.kofa.utils.helpers.attrs_to_fields>`. These class attributes ensure that corresponding attributes of instances of this class - when being added or changed - always meet the requirements of the schema. Another big advantage of such class attributes is, that attributes with a `FieldProperty` do not need to be set in `__init__` methods.
 
 
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig.pt
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig.pt	(revision 12970)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig.pt	(revision 12971)
@@ -74,5 +74,6 @@
   function test() {
       if (document.getElementById('exporter').value == 'bursary' ||
-          document.getElementById('exporter').value == 'studentpayments') {
+          document.getElementById('exporter').value == 'studentpayments' ||
+          document.getElementById('exporter').value == 'studentunpaidpayments') {
           document.getElementById('payment_dates').style.display = 'block';
       } else {
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig_certificate.pt
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig_certificate.pt	(revision 12970)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig_certificate.pt	(revision 12971)
@@ -64,5 +64,6 @@
   function test() {
       if (document.getElementById('exporter').value == 'bursary' ||
-          document.getElementById('exporter').value == 'studentpayments') {
+          document.getElementById('exporter').value == 'studentpayments' ||
+          document.getElementById('exporter').value == 'studentunpaidpayments') {
           document.getElementById('payment_dates').style.display = 'block';
       } else {
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/export.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/export.py	(revision 12970)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/export.py	(revision 12971)
@@ -86,5 +86,5 @@
     return tickets
 
-def get_payments(students, paid=False, **kw):
+def get_payments(students, p_state=None, **kw):
     """Get all payments of `students` within given payment_date period.
     """
@@ -100,9 +100,9 @@
         payments_start = tz.localize(payments_start)
         payments_end = tz.localize(payments_end)
-        if paid:
-            # Only paid tickets in payment period are considered
+        if p_state:
+            # Only paid or unpaid tickets in payment period are considered
             for student in students:
                 for payment in student.get('payments', {}).values():
-                    if payment.payment_date and payment.p_state == 'paid':
+                    if payment.payment_date and payment.p_state == p_state:
                         payment_date = to_timezone(payment.payment_date, tz)
                         if payment_date > payments_start and \
@@ -120,9 +120,9 @@
     else:
         # Payment period not given
-        if paid:
+        if p_state:
             # Only paid tickets are considered
             for student in students:
                 for payment in student.get('payments', {}).values():
-                    if payment.p_state == 'paid':
+                    if payment.p_state == p_state:
                         payments.append(payment)
         else:
@@ -382,4 +382,17 @@
             value, name, context=context)
 
+class StudentUnpaidPaymentExporter(StudentPaymentExporter):
+    """The Student Unpaid Payment Exporter works just like the
+    Student Payments Exporter but it exports only unpaid tickets.
+    This exporter is designed for finding and finally purging outdated
+    payment ticket.
+    """
+    grok.name('studentunpaidpayments')
+
+    title = _(u'Student Unpaid Payments')
+
+    def filter_func(self, x, **kw):
+        return get_payments(x, p_state='unpaid', **kw)
+
 class DataForBursaryExporter(StudentPaymentExporter):
     """The DataForBursary Exporter works just like the Student Payments Exporter
@@ -392,5 +405,5 @@
 
     def filter_func(self, x, **kw):
-        return get_payments(x, paid=True, **kw)
+        return get_payments(x, p_state='paid', **kw)
 
     fields = tuple(
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/student.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/student.py	(revision 12970)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/student.py	(revision 12971)
@@ -421,8 +421,8 @@
     """
 
-    STUDENT_EXPORTER_NAMES = getUtility(
-        IStudentsUtils).STUDENT_EXPORTER_NAMES
-
-    for name in STUDENT_EXPORTER_NAMES:
+    STUDENT_BACKUP_EXPORTER_NAMES = getUtility(
+        IStudentsUtils).STUDENT_BACKUP_EXPORTER_NAMES
+
+    for name in STUDENT_BACKUP_EXPORTER_NAMES:
         exporter = getUtility(ICSVStudentExporter, name=name)
         csv_data = exporter.export_student(student)
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 12970)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py	(revision 12971)
@@ -32,4 +32,5 @@
     StudentPaymentsOverviewExporter, StudentStudyLevelsOverviewExporter,
     ComboCardDataExporter, DataForBursaryExporter,
+    StudentUnpaidPaymentExporter,
     get_students,)
 from waeup.kofa.students.accommodation import BedTicket
@@ -895,4 +896,43 @@
         result = open(self.outfile, 'rb').read()
         
+        return
+
+class StudentUnpaidPaymentExporterTest(StudentImportExportSetup):
+
+    layer = FunctionalLayer
+
+    def setUp(self):
+        super(StudentUnpaidPaymentExporterTest, self).setUp()
+        self.setup_for_export()
+        return
+
+    def test_export_all(self):
+        # we can really export all payments
+        # set values we can expect in export file
+        self.setup_student(self.student)
+        exporter = StudentUnpaidPaymentExporter()
+        exporter.export_all(self.app, self.outfile)
+        result = open(self.outfile, 'rb').read()
+        # No unpaid ticket exists
+        self.assertEqual(
+            result,
+            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
+            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
+            'r_code,r_desc,student_id,state,current_session\r\n'
+            )
+        # Make ticket unpaid
+        self.payment.p_state = 'unpaid'
+        exporter.export_all(self.app, self.outfile)
+        result = open(self.outfile, 'rb').read()
+        self.assertEqual(
+            result,
+            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
+            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
+            'r_code,r_desc,student_id,state,current_session\r\n'
+
+            '666,12.12,2012-04-01 13:12:01#,schoolfee,1,my-id,'
+            'p-item,100,2012,unpaid,2012-04-01 14:12:01#,12.12,'
+            'r-code,,A111111,created,2012\r\n'
+            )
         return
 
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py	(revision 12970)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py	(revision 12971)
@@ -182,8 +182,8 @@
 
         # The student data were put into CSV files
-        STUDENT_EXPORTER_NAMES = getUtility(
-            IStudentsUtils).STUDENT_EXPORTER_NAMES
-
-        for name in STUDENT_EXPORTER_NAMES:
+        STUDENT_BACKUP_EXPORTER_NAMES = getUtility(
+            IStudentsUtils).STUDENT_BACKUP_EXPORTER_NAMES
+
+        for name in STUDENT_BACKUP_EXPORTER_NAMES:
             csv_path = os.path.join(del_dir, '%s.csv' % name)
             self.assertTrue(os.path.isfile(csv_path))
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py	(revision 12970)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py	(revision 12971)
@@ -954,6 +954,13 @@
     STUDENT_EXPORTER_NAMES = ('students', 'studentstudycourses',
             'studentstudylevels', 'coursetickets',
-            'studentpayments', 'bedtickets', 'paymentsoverview',
+            'studentpayments', 'studentunpaidpayments',
+            'bedtickets', 'paymentsoverview',
             'studylevelsoverview', 'combocard', 'bursary')
+
+    #: A tuple containing all exporter names needed for backing
+    #: up student data
+    STUDENT_BACKUP_EXPORTER_NAMES = ('students', 'studentstudycourses',
+            'studentstudylevels', 'coursetickets',
+            'studentpayments', 'bedtickets')
 
     #: A prefix used when generating new student ids. Each student id will
Index: /main/waeup.kofa/trunk/src/waeup/kofa/university/department.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/university/department.py	(revision 12970)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/university/department.py	(revision 12971)
@@ -31,5 +31,4 @@
 from waeup.kofa.utils.batching import VirtualExportJobContainer
 from waeup.kofa.interfaces import IKofaUtils, IKofaPluggable
-from waeup.kofa.utils.helpers import attrs_to_fields
 from waeup.kofa.university.interfaces import IDepartment
 
