'Quantity still needed for a track item - used in Inv Send
when an Item has come from a Request'

@staticmethod
def inv_track_item_quantity_needed(row):

    if hasattr(row, 'inv_track_item'):
        row = row.inv_track_item
    try:
        req_item_id = row.req_item_id
    except:
        req_item_id = None
    if (not req_item_id):
        return current.messages['NONE']
    s3db = current.s3db
    ritable = s3db.req_req_item
    siptable = s3db.supply_item_pack
    query = ((ritable.id == req_item_id) & (ritable.item_pack_id == siptable.id))
    row = current.db(query).select(ritable.quantity, ritable.quantity_transit, ritable.quantity_fulfil, siptable.quantity).first()
    if row:
        rim = row.req_req_item
        quantity_shipped = max(rim.quantity_transit, rim.quantity_fulfil)
        quantity_needed = ((rim.quantity - quantity_shipped) * row.supply_item_pack.quantity)
    else:
        return current.messages['NONE']
    return quantity_needed
