def update_requests_statuses(barcode, recid=None): if recid == None: recid = db.get_recid(barcode) list_of_pending_requests = db.get_requests(recid, CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING) some_copy_available = False copies_status = db.get_copies_status(recid) if copies_status is not None: for status in copies_status: if status in (CFG_BIBCIRCULATION_ITEM_STATUS_ON_SHELF, CFG_BIBCIRCULATION_ITEM_STATUS_IN_PROCESS): some_copy_available = True if len(list_of_pending_requests) == 1: if not some_copy_available: db.update_loan_request_status(list_of_pending_requests[0][0], CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING) else: return list_of_pending_requests[0][0] elif len(list_of_pending_requests) == 0: if some_copy_available: list_of_waiting_requests = db.get_requests(recid, CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING) if len(list_of_waiting_requests) > 0: db.update_loan_request_status(list_of_waiting_requests[0][0], CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING) return list_of_waiting_requests[0][0] elif len(list_of_pending_requests) > 1: for request in list_of_pending_requests: db.update_loan_request_status(request[0], CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING) list_of_waiting_requests = db.get_requests(recid, CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING) if some_copy_available: db.update_loan_request_status(list_of_waiting_requests[0][0], CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING) return list_of_waiting_requests[0][0] return None
def update_requests_statuses(barcode): recid = db.get_id_bibrec(barcode) description = db.get_item_description(barcode) list_of_pending_requests = db.get_requests( recid, description, CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING) some_copy_available = False copies_status = db.get_copies_status(recid, description) if copies_status is not None: for status in copies_status: if status in (CFG_BIBCIRCULATION_ITEM_STATUS_ON_SHELF, CFG_BIBCIRCULATION_ITEM_STATUS_IN_PROCESS): some_copy_available = True if len(list_of_pending_requests) == 1: if not some_copy_available: db.update_loan_request_status( CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING, list_of_pending_requests[0][0]) else: return list_of_pending_requests[0][0] elif len(list_of_pending_requests) == 0: if some_copy_available: list_of_waiting_requests = db.get_requests( recid, description, CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING) if len(list_of_waiting_requests) > 0: db.update_loan_request_status( CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING, list_of_waiting_requests[0][0]) return list_of_waiting_requests[0][0] elif len(list_of_pending_requests) > 1: for request in list_of_pending_requests: db.update_loan_request_status( CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING, request[0]) list_of_waiting_requests = db.get_requests( recid, description, CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING) if some_copy_available: db.update_loan_request_status( CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING, list_of_waiting_requests[0][0]) return list_of_waiting_requests[0][0] return None
def has_copies(recid): """ Verify if a recid is item (has copies) @param recid: identify the record. Primary key of bibrec @type recid: int @return boolean """ copies_status = db.get_copies_status(recid) if copies_status is None: return False else: if len(copies_status) == 0: return False else: return True
def all_copies_are_missing(recid): """ Verify if all copies of an item are missing @param recid: identify the record. Primary key of bibrec @type recid: int @return boolean """ copies_status = db.get_copies_status(recid) number_of_missing = 0 for (status) in copies_status: if status == 'missing': number_of_missing += 1 if number_of_missing == len(copies_status): return True else: return False