Index: /main/waeup.kofa/trunk/CHANGES.txt
===================================================================
--- /main/waeup.kofa/trunk/CHANGES.txt	(revision 15242)
+++ /main/waeup.kofa/trunk/CHANGES.txt	(revision 15243)
@@ -4,4 +4,7 @@
 1.6.1.dev0 (unreleased)
 =======================
+
+* Fix get_student_payment_stats. Department codes are not
+  unique. Use its path instead.
 
 * Implement study level 0 (Level Zero) option for storing
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py	(revision 15242)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py	(revision 15243)
@@ -3298,4 +3298,5 @@
     def _searchCatalog(self, session):
         cat = queryUtility(ICatalog, name='coursetickets_catalog')
+        # Attention: Also tickets of previous studycourses are found
         coursetickets = cat.searchResults(
             session=(session, session),
@@ -3442,4 +3443,5 @@
     def data(self, session):
         cat = queryUtility(ICatalog, name='coursetickets_catalog')
+        # Attention: Also tickets of previous studycourses are found
         coursetickets = cat.searchResults(
             session=(session, session),
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/reports/student_payment_statistics.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/reports/student_payment_statistics.py	(revision 15242)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/reports/student_payment_statistics.py	(revision 15243)
@@ -62,17 +62,12 @@
     payment_cats = tuple(sorted(payment_cats_dict.keys())) + ('Total',)
     if breakdown == 'faccode':
-        codes = tuple(sorted([x for x in site['faculties'].keys()],
+        paths = tuple(sorted([x for x in site['faculties'].keys()],
                                  key=lambda x: x.lower()))
-        paths = codes
     elif breakdown == 'depcode':
         faculties = site['faculties']
-        depcodes = []
         deppaths = []
         for fac in faculties.values():
             for dep in fac.values():
-                depcodes.append(dep.code)
                 deppaths.append('%s/%s' % (fac.code, dep.code))
-        codes = tuple(sorted([x for x in depcodes],
-                                 key=lambda x: x.lower()))
         paths = tuple(sorted([x for x in deppaths],
                                  key=lambda x: x.lower()))
@@ -87,5 +82,5 @@
         result = cat.searchResults(current_session=(session, session))
     table = [[0 for x in xrange(2*len(payment_cats))]
-                for y in xrange(len(codes)+1)]
+                for y in xrange(len(paths)+1)]
     mode_groups = getUtility(IKofaUtils).MODE_GROUPS
     for stud in result:
@@ -97,8 +92,14 @@
         if entry_session != 0 and  stud.entry_session != entry_session:
             continue
-        if getattr(stud, breakdown) not in codes:
-            # studs can have a faccode ``None``
-            continue
-        row = codes.index(getattr(stud, breakdown))
+        if breakdown == 'faccode':
+            if getattr(stud, 'faccode') not in paths:
+                # studs can have a faccode ``None``
+                continue
+        # Dep codes are not unique.
+        if breakdown == 'depcode':
+            row = paths.index(
+                '%s/%s' % (getattr(stud, 'faccode'), getattr(stud, 'depcode')))
+        else:
+            row = paths.index(getattr(stud, breakdown))
         for key in stud['payments'].keys():
             ticket = stud['payments'][key]
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_student_payment_statistics.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_student_payment_statistics.py	(revision 15242)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_student_payment_statistics.py	(revision 15243)
@@ -53,12 +53,22 @@
         return
 
-    def test_create_pdf(self):
+    def test_create_pdf_1(self):
         report = StudentPaymentStatisticsReport(
             2010, 'Undergraduate Full-Time', 0, 0, 0, 'faccode')
         result = report.create_pdf('JOB_ID')
         self.assertTrue(result.startswith('%PDF-'))
-        path = os.path.join(samples_dir(), 'student_payment_statistics.pdf')
+        path = os.path.join(samples_dir(), 'student_payment_statistics_faccode.pdf')
         open(path, 'wb').write(result)
-        print "Sample PDF student_statistics.pdf written to %s" % path
+        print "Sample PDF student_statistics_faccode.pdf written to %s" % path
+        return
+
+    def test_create_pdf_2(self):
+        report = StudentPaymentStatisticsReport(
+            2010, 'Undergraduate Full-Time', 0, 0, 0, 'depcode')
+        result = report.create_pdf('JOB_ID')
+        self.assertTrue(result.startswith('%PDF-'))
+        path = os.path.join(samples_dir(), 'student_payment_statistics_depcode.pdf')
+        open(path, 'wb').write(result)
+        print "Sample PDF student_statistics_depcode.pdf written to %s" % path
         return
 
