Ignore:
Timestamp:
13 Feb 2008, 16:33:21 (17 years ago)
Author:
joachim
Message:

check for free bed before releasing old.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/skins/waeup_accommodation/change_bed.py

    r3151 r3156  
    1313"""
    1414import logging
     15from Products.AdvancedQuery import Eq, Between, Le,In
     16   
    1517logger = logging.getLogger('Skins.change_bed')
    16 
    1718request = context.REQUEST
    1819redirect = request.RESPONSE.redirect
     
    3839    res = beds(student=student_id)
    3940    status = info['student_status']
    40     if len(res) == 0:
    41         logger.info('No bed allocated for %s' % (student_id))
    42         #return redirect("%s/%s" % (students.absolute_url(),student_id))
    43     else:
     41    while True:
     42        if len(res) == 0:
     43            psm = 'No bed allocated for %s' % (student_id)
     44            logger.info(psm)
     45            break
    4446        allocated_bed = res[0]
    45     code,bed = beds.searchAndReserveBed(student_id,status)
    46     if code > 0:
    47         if res:
    48             if allocated_bed.bed_type == status:
    49                 logger.info('Status %s of %s has not changed' % (status,student_id))
    50                 psm='Student status has not changed!'
    51                 return redirect("%s/%s/%s/waeup_document_view?portal_status_message=%s" % (students.absolute_url(),student_id,info['acco_id'],psm))
    52             logger.info('Bed status %s of %s has changed to %s' % (allocated_bed.bed_type,student_id,status))
    53             beds.modifyRecord(bed=allocated_bed.bed,student=beds.not_occupied)
    54             logger.info('Bed %s released' % (allocated_bed.bed))   
    55         d = {}
    56         d['bed'] = bed
    57         d['student_status'] = status
    58         acco_info = context.waeup_tool.getHallInfo(bed)
    59         d['acco_maint_code'] = acco_info.get('maintenance_code')
    60         d['acco_maint_fee'] = acco_info.get('maintenance_fee')
    61         acco_doc = info['acco_doc']
    62         acco_doc.edit(mapping=d)
    63         logger.info('Bed %s allocated to %s' % (bed,student_id))
    64         psm='Bed changed!'
    65         return redirect("%s/%s/%s/waeup_document_view?portal_status_message=%s" % (students.absolute_url(),student_id,info['acco_id'],psm))
    66     #acco_doc = info['acco_doc']
    67     #acco_doc.edit(mapping={'bed':"-- cancelled by officer due to failed bed change request --"})
    68     logger.info('New bed allocation for %s failed, code = %s' % (student_id,code))
    69     #logger.info('%s cancelled booking of bed %s by %s' % (member,bed,student_id))
    70     psm='Bed change failed!'
     47        if allocated_bed.bed_type == status:
     48            logger.info('Status %s of %s has not changed' % (status,student_id))
     49            psm='Student status has not changed!'
     50            break
     51            #return redirect("%s/%s/%s/waeup_document_view?portal_status_message=%s" % (students.absolute_url(),student_id,info['acco_id'],psm))
     52        logger.info('Bed status %s of %s has changed to %s' % (allocated_bed.bed_type,student_id,status))
     53        query = Eq('bed_type',status) & Eq('student',context.portal_accommodation.not_occupied)
     54        records = context.portal_accommodation.evalAdvancedQuery(query)
     55        if len(records) < 1:
     56            psm=''New bed allocation for %s failed, No bed free in category %s' % (student_id,status)
     57            logger.info(psm)
     58            psm='Bed change failed!'
     59            break
     60        beds.modifyRecord(bed=allocated_bed.bed,student=beds.not_occupied)
     61        logger.info('Bed %s released' % (allocated_bed.bed))   
     62        code,bed = beds.searchAndReserveBed(student_id,status)
     63        if code > 0:
     64            d = {}
     65            d['bed'] = bed
     66            d['student_status'] = status
     67            acco_info = context.waeup_tool.getHallInfo(bed)
     68            d['acco_maint_code'] = acco_info.get('maintenance_code')
     69            d['acco_maint_fee'] = acco_info.get('maintenance_fee')
     70            acco_doc = info['acco_doc']
     71            acco_doc.edit(mapping=d)
     72            logger.info('Bed %s allocated to %s' % (bed,student_id))
     73            psm='Bed changed!'
     74            break
     75            #return redirect("%s/%s/%s/waeup_document_view?portal_status_message=%s" % (students.absolute_url(),student_id,info['acco_id'],psm))
     76        #acco_doc = info['acco_doc']
     77        #acco_doc.edit(mapping={'bed':"-- cancelled by officer due to failed bed change request --"})
     78        logger.info('New bed allocation for %s failed, code = %s' % (student_id,code))
     79        #logger.info('%s cancelled booking of bed %s by %s' % (member,bed,student_id))
     80        psm='Bed change failed!'
    7181    return redirect("%s/%s/%s/waeup_document_view?portal_status_message=%s" % (students.absolute_url(),student_id,info['acco_id'],psm))
    7282
Note: See TracChangeset for help on using the changeset viewer.