'Helper method that will receive the sent shipment.
This supports two methods:
method = "warehouse"
This requires going to the receiving warehouse
Selecting the shipment (using the WB reference)
Opening each item and selecting the received totals
Then receive the shipment
method = "search"
Search for all received shipments
Select the matching WB reference
Opening each item and selecting the received totals
Then receive the shipment
Finally:
It will get the stock in the warehouse before and then after
and check that the stock levels have been properly increased'

def recv_sent_shipment(self, method, user, WB_ref, item_list):

    browser = self.browser
    if (method == 'search'):
        self.login(account=user, nexturl='inv/recv/search')
        el = browser.find_element_by_id('recv_search_simple')
        el.send_keys(WB_ref)
        browser.find_element_by_css_selector("input[type='submit']").submit()
        if (not self.dt_action()):
            fail(('Unable    to    select    the    incoming    shipment    with    reference    %s' % WB_ref))
    elif (method == 'warehouse'):
        return
    else:
        fail(('Unknown    method    of    %s' % method))
        return
    url = browser.current_url
    url_parts = url.split('/')
    try:
        recv_id = int(url_parts[(-1)])
    except:
        recv_id = int(url_parts[(-2)])
    self.login(account=user, nexturl=('inv/recv/%s/track_item' % recv_id))
    data = []
    for item in item_list:
        self.dt_filter(item[0])
        self.dt_action()
        el = browser.find_element_by_id('inv_track_item_recv_quantity')
        el.send_keys(item[1])
        text = ('%s    %s' % (item[1], item[0]))
        data.append({'text': text, 'record': item[2]})
        browser.find_element_by_css_selector("input[type='submit']").submit()
    self.recv_shipment(user, recv_id, data)
