#NEWLINE# def req_items_for_inv( site_id , quantity_type ) : #NEWLINE# #INDENT# '\n        Used by recv_process & send_process\n        returns a dict of unique req items (with min  db.req_req.date_required | db.req_req.date)\n        key = item_id\n        @param site_id: The inventory to find the req_items from\n        @param quantity_type: str ("commit", "transit" or "fulfil) The\n                              quantity type which will be used to determine if this item is still outstanding\n    ' #NEWLINE# if ( not settings . has_module ( 'req' ) ) : #NEWLINE# #INDENT# return Storage ( ) #NEWLINE# #UNINDENT# table = s3db . req_req #NEWLINE# itable = s3db . req_req_item #NEWLINE# query = ( ( ( ( ( ( ( table . site_id == site_id ) & ( table . id == itable . req_id ) ) & ( itable . item_pack_id == itable . item_pack_id ) ) & ( itable [ ( 'quantity_%s' % quantity_type ) ] < itable . quantity ) ) & ( table . cancel == False ) ) & ( table . deleted == False ) ) & ( itable . deleted == False ) ) #NEWLINE# req_items = db ( query ) . select ( itable . id , itable . req_id , itable . item_id , itable . quantity , itable [ ( 'quantity_%s' % quantity_type ) ] , itable . item_pack_id , orderby = ( table . date_required | table . date ) ) #NEWLINE# req_item_ids = [ ] #NEWLINE# unique_req_items = Storage ( ) #NEWLINE# for req_item in req_items : #NEWLINE# #INDENT# if ( req_item . item_id not in req_item_ids ) : #NEWLINE# #INDENT# unique_req_items [ req_item . item_id ] = Storage ( req_item . as_dict ( ) ) #NEWLINE# req_item_ids . append ( req_item . item_id ) #NEWLINE# #UNINDENT# #UNINDENT# return unique_req_items