'Helper method that will receive the shipment, adding the
totals that arrived
It will get the stock in the warehouse before and then after
and check that the stock levels have been properly increased'

def recv_shipment(self, user, recv_id, data):

    db = current.db
    s3db = current.s3db
    rvtable = s3db.inv_recv
    iitable = s3db.inv_inv_item
    query = (rvtable.id == recv_id)
    record = db(query).select(rvtable.site_id, limitby=(0, 1)).first()
    site_id = record.site_id
    query = (iitable.site_id == site_id)
    before = db(query).select(orderby=iitable.id)
    self.login(account=user, nexturl=('inv/recv_process/%s' % recv_id))
    db.commit()
    query = (iitable.site_id == site_id)
    after = db(query).select(orderby=iitable.id)
    changes = []
    for a_rec in after:
        found = False
        for b_rec in before:
            if (a_rec.id == b_rec.id):
                if (a_rec.quantity != b_rec.quantity):
                    changes.append((a_rec.item_id, a_rec.item_pack_id, (a_rec.quantity - b_rec.quantity)))
                found = True
                break
        if (not found):
            changes.append((a_rec.item_id, a_rec.item_pack_id, a_rec.quantity))
    self.assertTrue((len(data) == len(changes)), ("The    number    of    changed    inventory    items    (%s)    doesn't    match    the    number    of    items    received        (%s)." % (len(changes), len(data))))
    for line in data:
        rec = line['record']
        found = False
        for change in changes:
            if ((rec.inv_track_item.item_id == change[0]) and (rec.inv_track_item.item_pack_id == change[1]) and (rec.inv_track_item.quantity == change[2])):
                found = True
                break
        if found:
            s3_debug(('%s    accounted    for.' % line['text']))
        else:
            s3_debug(('%s    not    accounted    for.' % line['text']))
