'Create a Shipment containing all items in a Commitment'

@staticmethod
def req_send_commit():

    try:
        commit_id = current.request.args[0]
    except:
        redirect(URL(c='req', f='commit'))
    db = current.db
    s3db = current.s3db
    req_table = db.req_req
    rim_table = db.req_req_item
    com_table = db.req_commit
    cim_table = db.req_commit_item
    send_table = s3db.inv_send
    tracktable = s3db.inv_track_item
    query = (((com_table.id == commit_id) & (com_table.req_id == req_table.id)) & (com_table.deleted == False))
    record = db(query).select(com_table.committer_id, com_table.site_id, com_table.organisation_id, req_table.requester_id, req_table.site_id, req_table.req_ref, limitby=(0, 1)).first()
    form_vars = Storage(sender_id=record.req_commit.committer_id, site_id=record.req_commit.site_id, recipient_id=record.req_req.requester_id, to_site_id=record.req_req.site_id, req_ref=record.req_req.req_ref, status=0)
    send_id = send_table.insert(**form_vars)
    form_vars.id = send_id
    query = (((cim_table.commit_id == commit_id) & (cim_table.req_item_id == rim_table.id)) & (cim_table.deleted == False))
    records = db(query).select(rim_table.id, rim_table.item_id, rim_table.item_pack_id, rim_table.currency, rim_table.quantity, rim_table.quantity_transit, rim_table.quantity_fulfil, cim_table.quantity)
    insert = tracktable.insert
    for row in records:
        rim = row.req_req_item
        id = insert(req_item_id=rim.id, track_org_id=record.req_commit.organisation_id, send_id=send_id, status=1, item_id=rim.item_id, item_pack_id=rim.item_pack_id, currency=rim.currency, quantity=row.req_commit_item.quantity, recv_quantity=row.req_commit_item.quantity)
    form = Storage()
    form.vars = form_vars
    s3db.inv_send_onaccept(form)
    redirect(URL(f='send', args=[send_id]))
