Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_move.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_move.py	(revision 9341)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_move.py	(revision 9341)
@@ -0,0 +1,64 @@
+## $Id$
+## 
+## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+## 
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+## 
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+"""
+Tests for moving objects in faculties.
+"""
+import os
+from zope.catalog.interfaces import ICatalog
+from zope.component import queryUtility
+from waeup.kofa.university.department import Department
+from waeup.kofa.students.tests.test_browser import StudentsFullSetup
+
+class MoveObjectsInFaculties(StudentsFullSetup):
+
+    def test_move_certificate(self):
+        self.assertEqual(
+            self.app['faculties']['fac1']['dep1'].certificates['CERT1'],
+            self.certificate)
+        self.app['faculties']['fac1']['dep2'] = Department(code='dep2')
+        self.certificate.moveCertificate('fac1', 'dep2')
+        self.assertEqual(
+            self.app['faculties']['fac1']['dep2'].certificates['CERT1'],
+            self.certificate)
+        self.assertEqual(
+            [key for key in self.app['faculties']['fac1'][
+                'dep2'].certificates['CERT1'].keys()],
+            [u'COURSE1_100'])
+        self.assertEqual(
+            self.student['studycourse'].certificate,
+            self.certificate)
+
+        # We can still find the certificate in the catalog
+        cat = queryUtility(ICatalog, name='certificates_catalog')
+        results = cat.searchResults(code=('CERT1','CERT1'))
+        results = [x for x in results] # Turn results generator into list
+        assert len(results) == 1
+        assert results[0] is self.certificate
+
+        # We can find the student studying in the new department
+        cat = queryUtility(ICatalog, name='students_catalog')
+        results = cat.searchResults(depcode=('dep2','dep2'))
+        results = [x for x in results] # Turn results generator into list
+        assert len(results) == 1
+        assert results[0] is self.app['students'][self.student_id]
+        logfile = os.path.join(
+            self.app['datacenter'].storage, 'logs', 'students.log')
+        logcontent = open(logfile).read()
+        self.assertTrue('INFO - system - K1000000 - Certificate moved'
+            in logcontent)
+
Index: /main/waeup.kofa/trunk/src/waeup/kofa/university/certificate.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/university/certificate.py	(revision 9340)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/university/certificate.py	(revision 9341)
@@ -88,4 +88,19 @@
         return
 
+    def moveCertificate(self, fac, dep):
+        self.moved = True
+        cert = self
+        del self.__parent__[cert.code]
+        grok.getSite()['faculties'][fac][dep].certificates[cert.code] = cert
+        self.__parent__._p_changed = True
+        cat = getUtility(ICatalog, name='students_catalog')
+        results = cat.searchResults(certcode=(cert.code, cert.code))
+        for student in results:
+            notify(grok.ObjectModifiedEvent(student))
+            student.__parent__.logger.info(
+                '%s - Certificate moved' % student.__name__)
+
+        return
+
 class CertificateFactory(grok.GlobalUtility):
     """A factory for certificates.
@@ -138,4 +153,8 @@
     student studycourse objects are removed.
     """
+    # Do not remove referrer if certificate is going to move
+    if getattr(certificate, 'moved', False):
+        return
+
     code = certificate.code
 
