Index: WAeUP_SRP/base/skins/waeup_accommodation/change_bed.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_accommodation/change_bed.py	(revision 3254)
+++ WAeUP_SRP/base/skins/waeup_accommodation/change_bed.py	(revision 3406)
@@ -43,22 +43,27 @@
             psm = 'No bed allocated for %s' % (student_id)
             logger.info(psm)
-            break
-        allocated_bed = res[0]
-        if allocated_bed.bed_type == status:
-            logger.info('Status %s of %s has not changed.' % (status,student_id))
-            psm='Student status has not changed!'
-            break
-            #return redirect("%s/%s/%s/waeup_document_view?portal_status_message=%s" % (students.absolute_url(),student_id,info['acco_id'],psm))
-        logger.info('Bed status %s of %s has changed to %s.' % (allocated_bed.bed_type,student_id,status))
-        query = Eq('bed_type',status) & Eq('student',context.portal_accommodation.not_occupied)
-        records = context.portal_accommodation.evalAdvancedQuery(query)
-        if len(records) < 1:
-            psm='Bed change for %s failed, no free bed in category %s.' % (student_id,status)
-            logger.info(psm)
-            break
-        beds.modifyRecord(bed=allocated_bed.bed,student=beds.not_occupied)
-        logger.info('Bed %s released' % (allocated_bed.bed))
+            pass
+            #break
+        elif res[0].bed_type.endswith("reserved"):
+             logger.info('found reserved bed %s' % res[0].bed)
+             pass        
+        else:    
+            allocated_bed = res[0]
+            if allocated_bed.bed_type == status:
+                logger.info('Status %s of %s has not changed.' % (status,student_id))
+                psm='Student status has not changed!'
+                break
+                #return redirect("%s/%s/%s/waeup_document_view?portal_status_message=%s" % (students.absolute_url(),student_id,info['acco_id'],psm))
+            logger.info('Bed status %s of %s has changed to %s.' % (allocated_bed.bed_type,student_id,status))
+            query = Eq('bed_type',status) & Eq('student',context.portal_accommodation.not_occupied)
+            records = context.portal_accommodation.evalAdvancedQuery(query)
+            if len(records) < 1:
+                psm='Bed change for %s failed, no free bed in category %s.' % (student_id,status)
+                logger.info(psm)
+                break
+            beds.modifyRecord(bed=allocated_bed.bed,student=beds.not_occupied)
+            logger.info('Bed %s released' % (allocated_bed.bed))
         code,bed = beds.searchAndReserveBed(student_id,status)
-        if code > 0:
+        if code > -2:
             d = {}
             d['bed'] = bed
@@ -72,10 +77,7 @@
             psm='Bed changed!'
             break
-            #return redirect("%s/%s/%s/waeup_document_view?portal_status_message=%s" % (students.absolute_url(),student_id,info['acco_id'],psm))
-        #acco_doc = info['acco_doc']
-        #acco_doc.edit(mapping={'bed':"-- cancelled by officer due to failed bed change request --"})
         logger.info('Bed change for %s failed, code = %s' % (student_id,code))
-        #logger.info('%s cancelled booking of bed %s by %s' % (member,bed,student_id))
         psm='Bed change failed!'
+        break
     return redirect("%s/%s/%s/waeup_document_view?portal_status_message=%s" % (students.absolute_url(),student_id,info['acco_id'],psm))
 
Index: WAeUP_SRP/base/skins/waeup_accommodation/reallocate_bed.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_accommodation/reallocate_bed.py	(revision 3254)
+++ 	(revision )
@@ -1,107 +1,0 @@
-## Script (Python) "reallocate_bed"
-##bind container=container
-##bind context=context
-##bind namespace=
-##bind script=script
-##bind subpath=traverse_subpath
-##parameters=
-##title=
-##
-# $Id: reallocateBed.py 1206 2007-01-05 18:24:56Z joachim $
-"""
-reallocate beds
-"""
-import logging
-logger = logging.getLogger('Skins.reallocate_bed')
-
-request = context.REQUEST
-redirect = request.RESPONSE.redirect
-mtool = context.portal_membership
-wf = context.portal_workflow
-member = mtool.getAuthenticatedMember()
-member_id = str(member)
-path_info = request.get('PATH_INFO').split('/')
-
-if mtool.isAnonymousUser():
-    return None
-students = context.portal_url.getPortalObject().campus.students
-beds = context.portal_accommodation
-studs = context.students_catalog
-student_id = context.getStudentId()
-
-if student_id is not None:
-    logger.info('%s requests bed_change for %s' % (member_id,student_id))
-    info = context.getAccommodationInfo(student_id)
-    res = beds(student=student_id)
-    if len(res) == 0:
-        logger.info('No bed found for %s' % (student_id))
-        redirect("%s/%s" % (students.absolute_url(),student_id))
-    allocated_bed = res[0]
-    status = info['student_status']
-    student = student_id
-    bedtype = context.getBedStatusFromHall(allocated_bed.bed)
-    if not bedtype.endswith("reserved"):
-        logger.info('%s is NOT a reserved bed' % (bedtype))
-        return redirect("%s/%s/%s" % (students.absolute_url(),student,info['acco_id']))
-    logger.info('%s reallocate reserved bed %s/%s' % (student_id,bedtype,status))
-    beds.modifyRecord(bed=allocated_bed.bed,
-                      student='',
-                      bed_type=bedtype)
-    code,bed = beds.searchAndReserveBed(student_id,status)
-    if code > 0:
-        #from Products.zdb import set_trace; set_trace()
-        d = {}
-        d['bed'] = bed
-        d['student_status'] = status
-        acco_info = context.waeup_tool.getHallInfo(bed)
-        d['acco_maint_code'] = acco_info.get('maintenance_code')
-        d['acco_maint_fee'] = acco_info.get('maintenance_fee')
-        acco_doc = info['acco_doc']
-        acco_doc.edit(mapping=d)
-        return redirect("%s/%s/%s" % (students.absolute_url(),student,info['acco_id']))
-    logger.info('%s new bed allocation failed, code = %s' % (student_id,code))
-    return redirect("%s/%s/%s" % (students.absolute_url(),student,info['acco_id']))
-
-info = {}
-#records = [r for r in beds() if  r.student]
-records = beds.uniqueValuesFor('bed')
-list = []
-to_modify = []
-for b in records:
-    r = beds(bed=b)[0]
-    bedtype = context.getBedStatusFromHall(r.bed)
-    if not bedtype.endswith("reserved"):
-        #logger.info('"%s", "allocated bed is NOT reserved","%s"' % (student_id,bedtype))
-        #list.append("Student %s bed_type %s ok" % (r.student,bedtype))
-        continue
-    if not r.student:
-        beds.modifyRecord(bed=b,
-                      bed_type=bedtype)
-        list.append("Empty bed %s set to %s" % (r.bed,bedtype))
-        continue
-    info = context.getAccommodationInfo(r.student)
-    sbt = info.get('student_status',None)
-    if sbt is None:
-        continue
-    list.append("Student %s bed_type %s != %s" % (r.student,
-                                                  r.bed_type,
-                                                  bedtype))
-    to_modify.append((r.bed,r.student,info['student_status'],info['acco_doc'],bedtype))
-for former_bed, student, status,acco_doc,bedtype in to_modify:
-    beds.modifyRecord(bed=former_bed,
-                      student='',
-                      bed_type=bedtype)
-    code,bed = beds.searchAndReserveBed(student,status)
-    if code > 0:
-        #from Products.zdb import set_trace; set_trace()
-        d = {}
-        d['bed'] = bed
-        d['student_status'] = status
-        acco_info = context.waeup_tool.getHallInfo(bed)
-        d['acco_maint_code'] = acco_info.get('maintenance_code')
-        d['acco_maint_fee'] = acco_info.get('maintenance_fee')
-        acco_doc.edit(mapping=d)
-        list.append("Student %s got bed %s, code = %s" % (student,
-                                                              bed,
-                                                              code))
-return "\r".join(list)
Index: WAeUP_SRP/base/skins/waeup_accommodation/reallocate_bed.py_not_used
===================================================================
--- WAeUP_SRP/base/skins/waeup_accommodation/reallocate_bed.py_not_used	(revision 3406)
+++ WAeUP_SRP/base/skins/waeup_accommodation/reallocate_bed.py_not_used	(revision 3406)
@@ -0,0 +1,107 @@
+## Script (Python) "reallocate_bed"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=
+##title=
+##
+# $Id: reallocateBed.py 1206 2007-01-05 18:24:56Z joachim $
+"""
+reallocate beds
+"""
+import logging
+logger = logging.getLogger('Skins.reallocate_bed')
+
+request = context.REQUEST
+redirect = request.RESPONSE.redirect
+mtool = context.portal_membership
+wf = context.portal_workflow
+member = mtool.getAuthenticatedMember()
+member_id = str(member)
+path_info = request.get('PATH_INFO').split('/')
+
+if mtool.isAnonymousUser():
+    return None
+students = context.portal_url.getPortalObject().campus.students
+beds = context.portal_accommodation
+studs = context.students_catalog
+student_id = context.getStudentId()
+
+if student_id is not None:
+    logger.info('%s requests bed_change for %s' % (member_id,student_id))
+    info = context.getAccommodationInfo(student_id)
+    res = beds(student=student_id)
+    if len(res) == 0:
+        logger.info('No bed found for %s' % (student_id))
+        redirect("%s/%s" % (students.absolute_url(),student_id))
+    allocated_bed = res[0]
+    status = info['student_status']
+    student = student_id
+    bedtype = context.getBedStatusFromHall(allocated_bed.bed)
+    if not bedtype.endswith("reserved"):
+        logger.info('%s is NOT a reserved bed' % (bedtype))
+        return redirect("%s/%s/%s" % (students.absolute_url(),student,info['acco_id']))
+    logger.info('%s reallocate reserved bed %s/%s' % (student_id,bedtype,status))
+    beds.modifyRecord(bed=allocated_bed.bed,
+                      student='',
+                      bed_type=bedtype)
+    code,bed = beds.searchAndReserveBed(student_id,status)
+    if code > 0:
+        #from Products.zdb import set_trace; set_trace()
+        d = {}
+        d['bed'] = bed
+        d['student_status'] = status
+        acco_info = context.waeup_tool.getHallInfo(bed)
+        d['acco_maint_code'] = acco_info.get('maintenance_code')
+        d['acco_maint_fee'] = acco_info.get('maintenance_fee')
+        acco_doc = info['acco_doc']
+        acco_doc.edit(mapping=d)
+        return redirect("%s/%s/%s" % (students.absolute_url(),student,info['acco_id']))
+    logger.info('%s new bed allocation failed, code = %s' % (student_id,code))
+    return redirect("%s/%s/%s" % (students.absolute_url(),student,info['acco_id']))
+
+info = {}
+#records = [r for r in beds() if  r.student]
+records = beds.uniqueValuesFor('bed')
+list = []
+to_modify = []
+for b in records:
+    r = beds(bed=b)[0]
+    bedtype = context.getBedStatusFromHall(r.bed)
+    if not bedtype.endswith("reserved"):
+        #logger.info('"%s", "allocated bed is NOT reserved","%s"' % (student_id,bedtype))
+        #list.append("Student %s bed_type %s ok" % (r.student,bedtype))
+        continue
+    if not r.student:
+        beds.modifyRecord(bed=b,
+                      bed_type=bedtype)
+        list.append("Empty bed %s set to %s" % (r.bed,bedtype))
+        continue
+    info = context.getAccommodationInfo(r.student)
+    sbt = info.get('student_status',None)
+    if sbt is None:
+        continue
+    list.append("Student %s bed_type %s != %s" % (r.student,
+                                                  r.bed_type,
+                                                  bedtype))
+    to_modify.append((r.bed,r.student,info['student_status'],info['acco_doc'],bedtype))
+for former_bed, student, status,acco_doc,bedtype in to_modify:
+    beds.modifyRecord(bed=former_bed,
+                      student='',
+                      bed_type=bedtype)
+    code,bed = beds.searchAndReserveBed(student,status)
+    if code > 0:
+        #from Products.zdb import set_trace; set_trace()
+        d = {}
+        d['bed'] = bed
+        d['student_status'] = status
+        acco_info = context.waeup_tool.getHallInfo(bed)
+        d['acco_maint_code'] = acco_info.get('maintenance_code')
+        d['acco_maint_fee'] = acco_info.get('maintenance_fee')
+        acco_doc.edit(mapping=d)
+        list.append("Student %s got bed %s, code = %s" % (student,
+                                                              bed,
+                                                              code))
+return "\r".join(list)
Index: WAeUP_SRP/base/skins/waeup_accommodation/release_bed.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_accommodation/release_bed.py	(revision 3254)
+++ WAeUP_SRP/base/skins/waeup_accommodation/release_bed.py	(revision 3406)
@@ -44,5 +44,5 @@
     acco_cat.modifyRecord(bed=allocated_bed.bed,student=acco_cat.not_occupied)
     acco_doc = context.getContent()
-    acco_doc.edit(mapping={'bed':"-- cancelled by section officer --"})
+    acco_doc.edit(mapping={'bed':"-- cancelled by section officer --",'acco_maint_fee':""})
     logger.info('%s released bed of %s' % (member_id,student_id))
     return redirect("%s" % (context.absolute_url()))
