'Custom Method to commit to a Request
- creates a commit with commit_items for each req_item or
commit_skills for each req_skill'

@staticmethod
def req_commit_all(r, **attr):

    T = current.T
    db = current.db
    s3db = current.s3db
    table = s3db.req_commit
    record = r.record
    req_id = record.id
    query = ((table.req_id == req_id) & (table.deleted == False))
    exists = db(query).select(table.id, limitby=(0, 1))
    if exists:
        redirect(URL(f='req', args=[r.id, 'commit']))
    type = record.type
    cid = table.insert(req_id=req_id, type=type)
    if (type == 1):
        ritable = s3db.req_req_item
        items = db((ritable.req_id == req_id)).select(ritable.id, ritable.item_pack_id, ritable.quantity, ritable.comments)
        if items:
            citable = s3db.req_commit_item
            insert = citable.insert
            for item in items:
                id = item.id
                quantity = item.quantity
                insert(commit_id=cid, req_item_id=id, item_pack_id=item.item_pack_id, quantity=quantity, comments=item.comments)
                db((ritable.id == item.id)).update(quantity_commit=quantity)
        db((s3db.req_req.id == req_id)).update(commit_status=REQ_STATUS_COMPLETE)
        msg = T('You    have    committed    to    all    items    in    this    Request.    Please    check    that    all    details    are    correct    and    update    as-required.')
    elif (type == 3):
        rstable = s3db.req_req_skill
        skills = db((rstable.req_id == req_id)).select(rstable.id, rstable.skill_id, rstable.quantity, rstable.comments)
        if skills:
            cstable = s3db.req_commit_skill
            insert = cstable.insert
            for skill in skills:
                id = skill.id
                quantity = skill.quantity
                insert(commit_id=cid, skill_id=skill.skill_id, quantity=quantity, comments=skill.comments)
                db((rstable.id == skill.id)).update(quantity_commit=quantity)
        db((s3db.req_req.id == req_id)).update(commit_status=REQ_STATUS_COMPLETE)
        msg = T('You    have    committed    for    all    people    in    this    Request.    Please    check    that    all    details    are    correct    and    update    as-required.')
    else:
        db((s3db.req_req.id == req_id)).update(commit_status=REQ_STATUS_COMPLETE)
        msg = T('You    have    committed    to    this    Request.    Please    check    that    all    details    are    correct    and    update    as-required.')
    if ('send' in r.args):
        redirect(URL(f='send_commit', args=[cid]))
    elif ('assign' in r.args):
        redirect(URL(f='commit', args=[cid, 'assign']))
    else:
        current.session.confirmation = msg
        redirect(URL(c='req', f='commit', args=[cid]))
