Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py	(revision 13049)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py	(revision 13050)
@@ -2046,4 +2046,5 @@
         if len(entries):
             # If bed space has been manually allocated use this bed
+            manual = True
             bed = [entry for entry in entries][0]
             # Safety belt for paranoids: Does this bed really exist on portal?
@@ -2057,4 +2058,5 @@
         else:
             # else search for other available beds
+            manual = False
             entries = cat.searchResults(
                 bed_type=(acc_details['bt'],acc_details['bt']))
@@ -2084,4 +2086,9 @@
                 self.flash(_('Activation code has already been used.'),
                            type="warning")
+                if not manual:
+                    # Release the previously booked bed
+                    bed.owner = NOT_OCCUPIED
+                    # Catalog must be informed
+                    notify(grok.ObjectModifiedEvent(bed))
                 return
             else:
@@ -2089,8 +2096,14 @@
                 # Here we know that the ac is in state initialized so we do not
                 # expect an exception, but the owner might be different
-                if not invalidate_accesscode(
-                    pin,comment,self.context.student.student_id):
+                success = invalidate_accesscode(
+                    pin, comment, self.context.student.student_id)
+                if not success:
                     self.flash(_('You are not the owner of this access code.'),
                                type="warning")
+                    if not manual:
+                        # Release the previously booked bed
+                        bed.owner = NOT_OCCUPIED
+                        # Catalog must be informed
+                        notify(grok.ObjectModifiedEvent(bed))
                     return
         # Create bed ticket
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py	(revision 13049)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py	(revision 13050)
@@ -3006,5 +3006,5 @@
         self.assertMatches('...Activation Code:...',
                            self.browser.contents)
-        # Student can't used faked ACs ...
+        # Student can't use faked ACs ...
         self.browser.getControl(name="ac_series").value = u'nonsense'
         self.browser.getControl(name="ac_number").value = sfenumber
@@ -3019,4 +3019,7 @@
         self.assertMatches('...You are not the owner of this access code...',
                            self.browser.contents)
+        # The bed remains empty
+        bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
+        self.assertTrue(bed.owner == NOT_OCCUPIED)
         ac.owner = self.student_id
         self.browser.getControl(name="ac_series").value = sfeseries
@@ -3026,5 +3029,4 @@
                            self.browser.contents)
         # Bed has been allocated
-        bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
         self.assertTrue(bed.owner == self.student_id)
         # BedTicketAddPage is now blocked
