def req_item_in_shipment(shipment_item, shipment_type, req_items):
 shipment_item_table = ('inv_%s_item' % shipment_type)
 try:
  item_id = shipment_item[shipment_item_table].item_id
 except:
  item_id = shipment_item.inv_inv_item.item_id
 if (item_id in req_items):
  shipment_to_req_type = dict(recv='fulfil', send='transit')
  quantity_req_type = ('quantity_%s' % shipment_to_req_type[shipment_type])
  req_item = req_items[item_id]
  req_item_id = req_item.id
  quantity = (req_item[quantity_req_type] + ((shipment_item[shipment_item_table].pack_quantity / req_item.pack_quantity) * shipment_item[shipment_item_table].quantity))
  quantity = min(quantity, req_item.quantity)
  s3db.req_req_item[req_item_id] = {quantity_req_type: quantity}
  s3db[shipment_item_table][shipment_item[shipment_item_table].id] = dict(req_item_id=req_item_id)
  return (req_item.req_id, req_item.id)
 else:
  return (None, None)

def req_item_in_shipment ( shipment_item , shipment_type , req_items ) : shipment_item_table = ( 'inv_%s_item' % shipment_type ) try : item_id = shipment_item [ shipment_item_table ] . item_id except : item_id = shipment_item . inv_inv_item . item_id if ( item_id in req_items ) : shipment_to_req_type = dict ( recv = 'fulfil' , send = 'transit' ) quantity_req_type = ( 'quantity_%s' % shipment_to_req_type [ shipment_type ] ) req_item = req_items [ item_id ] req_item_id = req_item . id quantity = ( req_item [ quantity_req_type ] + ( ( shipment_item [ shipment_item_table ] . pack_quantity / req_item . pack_quantity ) * shipment_item [ shipment_item_table ] . quantity ) ) quantity = min ( quantity , req_item . quantity ) s3db . req_req_item [ req_item_id ] = { quantity_req_type : quantity } s3db [ shipment_item_table ] [ shipment_item [ shipment_item_table ] . id ] = dict ( req_item_id = req_item_id ) return ( req_item . req_id , req_item . id ) else : return ( None , None )
checks if a shipment item is in a request and updates req_item and the shipment .