coding

# xtw 库存调整
# 这一段没有比对 原库位sp库存一致 没有做排除
import time
import numpy as np
import arrow
import requests
import pandas as pd
from openpyxl import Workbook
import json
wb = Workbook()
ws = wb.active
# title = ['69码','库位','调整后库存','当前库位上的库存','货主','sp码','备注','库存id','现存库位id','指定库位id']
title =['sp' ,'目标库位id', '期望库存', '调整库位id','目标库位库存'  ,'合计库存']

def time_trans(local):
    l = []

    for value in local.values:
        value =np.datetime64(value)
        value =pd.to_datetime(value)
        value =value.date()  # 关于 numpy.datetime64 转换为 datetime https://www.codenong.com/49204453/

        if pd.isna(value):
            k =2
            l.append(k)
        else:
            time =arrow.get(value).to('local')
            time_format = time.strftime('%Y-%m-%d')
            l.append(time_format)

    return  l

def time_to_utc(local):
    time =arrow.get(local).to('local')
    time_format = time.strftime('%Y-%m-%d')
    return  time_format

ws.append(title)
session_wms = requests.Session()
info =()
# 这个url是登陆入口
login_url = "https://apollo-api.xtw-tech.com/v1/auth/token"
inventories = []
inventories_MOVE = []
inventories_initialize =[]
inventories_move_only =[]
# 请求头文件Request Headers
headers = {
    # 'accept': 'application/json, text/plain, */*',
    # 'accept-encoding': 'gzip, deflate, br',
    # 'accept-language': 'zh-CN,zh;q=0.9',
    # 'content-length': '46',
    # 'content-type': 'application/json',
    'grpc-metadata-application-code': 'VENUS',
    # 'grpc-metadata-user-auth-token': 'null',
    # 'origin': 'https://mercury.xtw-tech.com',
    # 'referer': 'https://mercury.xtw-tech.com/',
    # 'sec-fetch-mode': 'cors',
    # 'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36'
}

# 登陆wms
data = {
    'username': "xujingfei",
    'password': "Xjf2567483"
}

# 登录wms
response_wms = session_wms.post(url=login_url, headers=headers, json=data)



adjust_data =  pd.read_excel('/Users/xujingfei/Desktop/收货信息/1216/2022_12_25_20221215收货商品明细/1217北京汇总.xlsx',sheet_name='Sheet13',engine='openpyxl')
# # 需要改变遍历方式
# 用于存储sp在该仓库的库位上的库存记录情况
# adjust_data['date'] = np.where(adjust_data['生产日期'].isna(),'2',time_trans(adjust_data['生产日期']))

def open(id):
    url =f'https://titan-api.xtw-tech.com/v1/inventory/by_id/{id}/enable'
    header ={
        'authority': 'titan-api.xtw-tech.com',
        'method': 'PUT',
        'path': f'/v1/inventory/by_id/{id}/enable',
        'scheme': 'https',
        'accept': 'application/json, text/plain, */*',
        'accept-encoding': 'gzip, deflate, br',
        'accept-language': 'zh-CN,zh;q=0.9',
        'grpc-metadata-application-code': 'MERCURY',
        'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
        'origin': 'https://mercury.xtw-tech.com',
        'referer': 'https://mercury.xtw-tech.com/',
        'sec-fetch-site': 'same-site',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36',

    }
    data = {'tenantId': "344"}

    st = session_wms.put(url=url,headers=header,data=json.dumps(data))
    status = st.status_code
    return  status


def start(sp):
    li = 'https://titan-api.xtw-tech.com/v1/inventory/list'
    header ={
        'authority': 'titan-api.xtw-tech.com',
        'method': 'POST',
        'path': '/v1/inventory/list',
        'scheme': 'https',
        'accept': 'application/json, text/plain, */*',
        'accept-encoding': 'gzip, deflate, br',
        'accept-language': 'zh-CN,zh;q=0.9',
        'content-length': '471',
        'content-type': 'application/json',
        'grpc-metadata-application-code': 'MERCURY',
        'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
        'origin': 'https://mercury.xtw-tech.com',
        'referer': 'https://mercury.xtw-tech.com/',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
    }
    data = {'tenantId': "344", 'listOption': {'page': '1', 'pageSize': '100', 'keyword': "",
                                              'sortBy': {'fieldToSort': "quantity", 'direction': "ASCENDING"},
                                              'fieldFilter': [{'fieldToFilter': "no_virtual_location", 'keyword': "1"},
                                                              {'fieldToFilter': "only_no_lot", 'keyword': "0"},
                                                              {'fieldToFilter': "sp_code", 'keyword': f"{sp}"},
                                                              {'fieldToFilter': "warehouse_ids", 'keyword': "741"},
                                                              {'fieldToFilter': "inventory_scrap_type",
                                                               'keyword': "normal"},
                                                              {'fieldToFilter': "inventory_lot_status", 'keyword': "valid"},
                                                              #把临期 过期 库位放出来了                      # {'fieldToFilter': "inventory_lot_status", 'keyword': "valid"},
                                                              {'fieldToFilter': "is_show_invalid", 'keyword': "1"},
                                                              {'fieldToFilter': "no_zero_inventory", 'keyword': "0"}],
                                              'keyword': ""}}
    invent_respon =session_wms.post(url=li,headers=header,json=data)
    item = invent_respon.json()['items']
    for i in item:
        sp_inventory_id = i['id']
        inventoryId = i['location']['id']
        lotEnabled =  i['lotEnabled']
        if inventoryId in  ['278271'] and lotEnabled ==True :
            t = open(sp_inventory_id)

            return t
            break
        elif inventoryId in  ['278271',] and lotEnabled ==False:
            t = open(sp_inventory_id)

            return t
            break
        elif inventoryId in  ['261312'] and lotEnabled ==True:
            t = open(sp_inventory_id)

            return t
            break
        elif inventoryId in  ['261312'] and lotEnabled ==False:
            t = open(sp_inventory_id)

            return t
            break
        else:
            continue







global inventorylist
inventorylist = {}
#用于存储sp在目标库位上的目标库存
in_list ={}
for i in range(len(adjust_data.index)):
    id = adjust_data.iloc[i, :11]
    ean_code = id.at['sp']
    sp_code = id.at['69码']
    # inventory_name_data = id.at['库位']
    # locationid = id.at['库位id']
    # date = id.at['date']
    date = '2'

    lot_data =  id.at['sp效期合计数量']  # 没有效期需要调整的库存数量
    total = id.at['total'] # 带有效期需要调整的库存数量
    if ean_code in in_list.keys():
        in_list[f'{ean_code}'][f'{date}']  = [lot_data,total]
    else:
        in_list[f'{ean_code}'] ={}
        in_list[f'{ean_code}'][f'{date}']  = [lot_data,total]

    #当前商品的库存价格 currentInventoryCost 、当前库存currentQuantity 库存id inventoryId
    li = 'https://titan-api.xtw-tech.com/v1/inventory/list'
    header ={
        'authority': 'titan-api.xtw-tech.com',
        'method': 'POST',
        'path': '/v1/inventory/list',
        'scheme': 'https',
        'accept': 'application/json, text/plain, */*',
        'accept-encoding': 'gzip, deflate, br',
        'accept-language': 'zh-CN,zh;q=0.9',
        'content-length': '471',
        'content-type': 'application/json',
        'grpc-metadata-application-code': 'MERCURY',
        'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
        'origin': 'https://mercury.xtw-tech.com',
        'referer': 'https://mercury.xtw-tech.com/',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
    }
    data = {'tenantId': "344", 'listOption': {'page': '1', 'pageSize': '100', 'keyword': "",
                                              'sortBy': {'fieldToSort': "quantity", 'direction': "ASCENDING"},
                                              'fieldFilter': [{'fieldToFilter': "no_virtual_location", 'keyword': "1"},
                                                              {'fieldToFilter': "only_no_lot", 'keyword': "0"},
                                                              {'fieldToFilter': "sp_code", 'keyword': f"{ean_code}"},
                                                              {'fieldToFilter': "warehouse_ids", 'keyword': "741"},
                                                              {'fieldToFilter': "inventory_scrap_type",
                                                               'keyword': "normal"},
        #把临期 过期 库位放出来了                      # {'fieldToFilter': "inventory_lot_status", 'keyword': "valid"},
                                                                {'fieldToFilter': "is_show_invalid", 'keyword': "0"},
                                                              {'fieldToFilter': "no_zero_inventory", 'keyword': "0"}],
                                              'keyword': ""}}
    invent_respon =session_wms.post(url=li,headers=header,json=data)
    item = invent_respon.json()['items']
    inventorylist[f'{ean_code}'] ={}
    price = 0
    count = 0
    for i in item:
        sp_inventory_id = i['id']
        currentInventoryCost = i['inventoryCost']
        currentQuantity = int(i['quantity'])
        inventoryId = i['location']['id']
        sp = i['standardProductTenantMapping']['standardProduct']['code']
        lotEnabled = i['lotEnabled']  # 若为True说明该sp在该warehouse开启了效期 反之没有开启效期 就算有生产日期也视作没有效期。先打一个问号?
        # 需要加入生产日期 以及是否开启效期
        try:
            productionTime = time_to_utc(i['lot']['productionTime'])
        except:
            productionTime='2'

        if inventoryId in inventorylist[f'{ean_code}'].keys()  :
            if inventoryId in ['278271'] and currentQuantity ==0:
                # 如何 将库存id也一块保存下来呢
                inventorylist[f'{ean_code}'][f'{inventoryId}'] = [sp_inventory_id,currentInventoryCost,productionTime,lotEnabled,currentQuantity]
            else:# 说明在278271库位下没有库存
                if inventoryId in ['261312'] and currentQuantity ==0:
                    inventorylist[f'{ean_code}'][f'{inventoryId}'] = [sp_inventory_id,currentInventoryCost,productionTime,lotEnabled,currentQuantity]  # 取默认库位上最大value
        else:
            if inventoryId in ['278271','261312']:
                inventorylist[f'{ean_code}'][f'{inventoryId}'] = [sp_inventory_id,currentInventoryCost,productionTime,lotEnabled,currentQuantity]
                continue
            else:
                continue
            print(f'{sp} {inventoryId}无默认库存、占用库存记录')

            # 可以考虑库存初始化
            '''
            url = 'https://titan-api.xtw-tech.com/v1/inventory/initialize'
            header = {
                authority: titan-api.xtw-tech.com
                method: POST
                path: /v1/inventory/initialize
                scheme: https
                accept: application/json, text/plain, */*
                accept-encoding: gzip, deflate, br
                accept-language: zh-CN,zh;q=0.9
                content-length: 97
                content-type: application/json
                grpc-metadata-application-code: MERCURY
                grpc-metadata-user-auth-token: ee57b4c8b7eb42ab41f4ced72ccd70670caf2db7ea7dab7f915e059e63620235
                origin: https://mercury.xtw-tech.com
                referer: https://mercury.xtw-tech.com/
                sec-ch-ua: "Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"
                sec-ch-ua-mobile: ?0
                sec-ch-ua-platform: "macOS"
                sec-fetch-dest: empty
                sec-fetch-mode: cors
                sec-fetch-site: same-site
                user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
            }
            data = {'spCodeList': ["SP452290038785240899"], 'ownerId': "41", 'warehouseIdList': ["741"], 'tenantId': "344"}        
            '''
for key,value in inventorylist.items():#库存库位启用
    if value=={}:
       k=  start(key)
       if k !=200:
           print(key)

# 区分 验收表里带有效期的 多个sp 、单sp

# print(in_list,'\n') # 需要按照目标库位分配执行库存
# print(inventorylist) # sp在仓库库位库存分布情况 (征用库位)
# 库存调整的时候需要库存id
# {'SP316347560706832409': {'2': [1, 1]}, 'SP133223833693974206': {'2022-05-19': [3, 27], '2021-05-29': [12, 27], '2022-05-29': [12, 27]}, 'SP165296143182220341': {'2021-09-30': [1, 1]}, 'SP789814726846110967': {'2': [3, 3]}, 'SP291607520194119002': {'2': [5, 5]}, 'SP577610921579835081': {'2': [1, 1]}, 'SP606023574461246323': {'2020-04-15': [1, 13], '2021-12-23': [12, 13]}, 'SP874792160710119915': {'2022-07-27': [3, 3]}, 'SP840901102085206421': {'2022-04-21': [16, 16]}, 'SP203074213931120030': {'2020-07-11': [2, 2]}, 'SP337000318555598710': {'2020-06-05': [2, 2]}, 'SP181529988370272781': {'2020-07-14': [1, 1]}, 'SP273957777682568919': {'2021-03-08': [5, 5]}, 'SP771445601899175633': {'2021-05-17': [1, 1]}, 'SP563694160254661155': {'2': [30, 30]}, 'SP150723570075786455': {'2021-02-21': [2, 2]}, 'SP373754536828767722': {'2020-10-08': [4, 4]}, 'SP470205760654365226': {'2020-10-15': [17, 17]}, 'SP233803092769099537': {'2021-03-21': [2, 3], '2': [1, 3]}, 'SP571844170447117605': {'2022-02-22': [4, 4]}, 'SP297777453347256540': {'2022-07-24': [4, 4]}, 'SP338783615674303140': {'2021-05-22': [1, 1]}, 'SP491955529541461074': {'2': [1, 1]}, 'SP251255411351967646': {'2': [1, 1]}, 'SP707627391517733135': {'2022-02-10': [1, 1]}, 'SP154552900631631962': {'2020-07-07': [10, 10]}, 'SP998793655916384187': {'2': [3, 3]}, 'SP700044998249240859': {'2022-08-14': [24, 24]}, 'SP474547154881518434': {'2020-09-27': [1, 1]}, 'SP523821352939217793': {'2021-01-19': [1, 1]}, 'SP774558186501534746': {'2022-04-29': [8, 8]}, 'SP439286162349540704': {'2022-11-12': [1, 1]}, 'SP115993875598660285': {'2021-03-05': [1, 2], '2021-04-11': [1, 2]}, 'SP699361327918574360': {'2': [2, 2]}, 'SP856176483488326236': {'2020-11-24': [1, 1]}, 'SP987061359765659605': {'2021-04-26': [1, 1]}, 'SP994670884976124521': {'2020-07-20': [1, 1]}, 'SP268030537694465597': {'2021-04-10': [1, 1]}, 'SP478208272219864897': {'2021-04-15': [1, 1]}, 'SP281750222902738072': {'2': [4, 4]}, 'SP745013244191056921': {'2021-09-22': [1, 1]}, 'SP248545274911927424': {'2021-09-25': [1, 1]}, 'SP424465070064716384': {'2': [7, 7]}, 'SP921429205033012874': {'2': [5, 5]}, 'SP918143438360030816': {'2': [14, 14]}, 'SP530858050221465010': {'2020-05-26': [6, 6]}, 'SP738885588167346513': {'2022-01-15': [2, 3], '2': [1, 3]}, 'SP241199036050032574': {'2022-07-14': [1, 1]}, 'SP214510114898633269': {'2020-11-01': [4, 4]}, 'SP105500776069534402': {'2': [5, 5]}, 'SP465704198199509776': {'2022-05-06': [8, 8]}, 'SP716702409998380511': {'2020-12-22': [1, 1]}, 'SP442121585565014696': {'2021-12-24': [2, 2]}, 'SP415539275588149882': {'2022-06-09': [16, 16]}, 'SP766205220545093876': {'2020-06-11': [1, 3], '2020-06-12': [2, 3]}, 'SP365699875106370579': {'2022-04-17': [1, 1]}, 'SP715081182195738511': {'2022-02-25': [2, 2]}, 'SP737099192051307797': {'2': [3, 3]}, 'SP658255897335144296': {'2': [3, 3]}, 'SP662935746919169932': {'2': [1, 1]}, 'SP535388457793115492': {'2': [6, 6]}, 'SP722550120252921006': {'2022-08-20': [120, 120]}, 'SP188238191959030625': {'2': [4, 4]}, 'SP142824499097026807': {'2022-03-18': [1, 1]}, 'SP424141639058481232': {'2': [1, 1]}, 'SP407949024296164571': {'2': [1, 1]}, 'SP830395898789953859': {'2021-09-13': [1, 1]}, 'SP158984521598975341': {'2020-12-10': [1, 1]}, 'SP866152273193250786': {'2': [14, 14]}, 'SP982557609358456594': {'2': [1, 1]}, 'SP569426960226066400': {'2021-10-20': [1, 1]}, 'SP407434842282674865': {'2022-03-23': [1, 1]}, 'SP797171849142001655': {'2020-07-31': [1, 1]}, 'SP338658217513546014': {'2022-06-27': [2, 2]}, 'SP922571684462910212': {'2020-12-15': [2, 2]}, 'SP612021720051611019': {'2021-11-27': [1, 1]}, 'SP728424123471133456': {'2022-03-04': [1, 1]}, 'SP941390436025829323': {'2022-06-20': [1, 1]}, 'SP425611646306366806': {'2022-04-07': [1, 1]}, 'SP410378343690228894': {'2021-09-17': [2, 2]}, 'SP237135355523307710': {'2022-05-13': [2, 2]}, 'SP583174914925323964': {'2020-05-20': [1, 1]}, 'SP306052198548187191': {'2021-11-08': [1, 1]}, 'SP707075511462393291': {'2022-05-27': [1, 1]}, 'SP214482385520239394': {'2': [4, 4]}, 'SP956421130402153227': {'2022-05-13': [1, 1]}, 'SP945779724001048936': {'2022-04-18': [1, 1]}, 'SP894783343542450173': {'2': [2, 2]}, 'SP148855163778317944': {'2022-05-31': [1, 1]}, 'SP884143455030275774': {'2021-11-04': [1, 1]}, 'SP843684092191854367': {'2022-02-10': [1, 1]}, 'SP631506692728349809': {'2022-04-02': [3, 3]}, 'SP713188272500749486': {'2022-05-28': [2, 2]}, 'SP658312135705812179': {'2021-11-12': [2, 2]}, 'SP764032813921242028': {'2022-07-12': [2, 2]}, 'SP946993337131438362': {'2': [1, 1]}, 'SP767162507942876684': {'2022-03-31': [12, 12]}, 'SP427786123354076814': {'2': [2, 2]}, 'SP195970733862418199': {'2': [1, 1]}, 'SP384258684918339646': {'2021-07-27': [6, 6]}, 'SP599181453198450889': {'2': [3, 3]}, 'SP209744011631827804': {'2': [7, 7]}, 'SP213402646510430900': {'2021-07-27': [1, 1]}, 'SP488264609841139127': {'2021-10-28': [1, 1]}, 'SP852090214045757133': {'2': [1, 1]}, 'SP769778601996140107': {'2021-11-12': [1, 1]}, 'SP112466934592380135': {'2022-06-15': [3, 3]}, 'SP580627243850801840': {'2021-07-07': [1, 1]}, 'SP995174729414211953': {'2': [2, 2]}, 'SP271840875840141717': {'2': [1, 1]}, 'SP667959356850754623': {'2': [2, 2]}, 'SP497955536980492879': {'2': [1, 1]}, 'SP498176087254196244': {'2': [1, 1]}, 'SP788171787727100995': {'2': [6, 6]}, 'SP845543020659527070': {'2': [4, 4]}, 'SP759754595746801567': {'2021-07-01': [5, 5]}, 'SP702163147095077684': {'2': [24, 24]}, 'SP215892937669688957': {'2': [2, 2]}, 'SP355040735821858698': {'2': [24, 24]}, 'SP257780504814775573': {'2022-03-23': [1, 1]}, 'SP140893702270209586': {'2022-05-20': [2, 2]}, 'SP938090363827364252': {'2': [2, 2]}, 'SP580762873033685770': {'2021-04-15': [1, 1]}, 'SP136386969201917290': {'2': [51, 51]}, 'SP870514578867272531': {'2': [6, 6]}, 'SP825033967715417364': {'2': [2, 2]}, 'SP762732147699112286': {'2': [3, 3]}, 'SP502984898937653725': {'2': [1, 1]}, 'SP594847097709960909': {'2': [1, 1]}, 'SP205136958952755332': {'2021-09-07': [1, 1]}, 'SP731114593433349417': {'2': [9, 9]}, 'SP235763366755878485': {'2': [7, 7]}, 'SP217344982838879921': {'2022-07-15': [25, 25]}, 'SP506008505626969271': {'2': [1, 1]}, 'SP806780881788309202': {'2020-09-29': [6, 6]}, 'SP442158786094919926': {'2': [1, 1]}, 'SP963370552497734692': {'2': [2, 2]}, 'SP505694197334946372': {'2021-03-04': [4, 4]}, 'SP253005868020762039': {'2020-09-09': [1, 1]}, 'SP212944099727182359': {'2': [333, 333]}, 'SP282695819287909022': {'2': [5, 5]}, 'SP704559491352820561': {'2022-06-26': [7, 7]}, 'SP410071559975103508': {'2': [6, 6]}, 'SP861505289081407035': {'2': [4, 4]}, 'SP154243759624299831': {'2': [1, 1]}, 'SP984400576003783846': {'2': [8, 8]}, 'SP786598043000128560': {'2': [16, 16]}, 'SP360205237070323800': {'2': [6, 6]}, 'SP426750374069326730': {'2': [1, 1]}, 'SP969278437137867454': {'2': [2, 2]}, 'SP924313692816215003': {'2022-01-21': [24, 24]}, 'SP711088942414209237': {'2022-04-13': [9, 9]}, 'SP167057214654964182': {'2022-08-02': [9, 9]}, 'SP507271472067697000': {'2022-04-04': [10, 10]}, 'SP516473449760649869': {'2': [16, 16]}, 'SP928929721992990049': {'2022-07-23': [8, 8]}, 'SP917288204422880139': {'2022-04-26': [1, 1]}, 'SP111425117457520180': {'2': [13, 13]}, 'SP693705899232525801': {'2022-03-04': [30, 30]}, 'SP853073229412285734': {'2': [2, 2]}, 'SP731863917845713944': {'2': [1, 1]}}
# {'SP316347560706832409': {'278271': ['8714909', '187.66', '2', False]}, 'SP133223833693974206': {'261312': ['8617738', '59.00', '2022-11-01', True]}, 'SP165296143182220341': {'261312': ['8633497', '0.00', '2', True]}, 'SP789814726846110967': {'261312': ['8618195', '115.00', '2', False]}, 'SP291607520194119002': {'261312': ['8802763', '0.00', '2', False]}, 'SP577610921579835081': {'261312': ['8802769', '0.00', '2', False]}, 'SP606023574461246323': {'261312': ['8618497', '18.96', '2022-11-01', True]}, 'SP874792160710119915': {'261312': ['8637137', '34.23', '2022-12-05', True]}, 'SP840901102085206421': {'278271': ['8790323', '82.38', '2022-05-22', False]}, 'SP203074213931120030': {'261312': ['8802781', '0.00', '2', True]}, 'SP337000318555598710': {'261312': ['8802765', '0.00', '2', True]}, 'SP181529988370272781': {'261312': ['8618579', '38.00', '2022-11-01', True]}, 'SP273957777682568919': {'278271': ['8788574', '51.68', '2021-01-06', False]}, 'SP771445601899175633': {'261312': ['8633490', '0.00', '2', True]}, 'SP563694160254661155': {'278271': ['8778654', '2.68', '2', False]}, 'SP150723570075786455': {'261312': ['8617262', '45.54', '2022-11-01', True]}, 'SP373754536828767722': {'261312': ['8802794', '0.00', '2', True]}, 'SP470205760654365226': {'261312': ['8634077', '0.00', '2', True]}, 'SP233803092769099537': {'261312': ['8618541', '25.00', '2022-11-01', True], '278271': ['8788576', '25.00', '2022-01-21', True]}, 'SP571844170447117605': {'261312': ['8618059', '3.20', '2022-11-01', True]}, 'SP297777453347256540': {'261312': ['8617632', '0.00', '2', False]}, 'SP338783615674303140': {'261312': ['8616863', '8.22', '2022-11-01', True]}, 'SP491955529541461074': {'261312': ['8660575', '0.00', '2', False]}, 'SP251255411351967646': {'261312': ['8618327', '46.80', '2', False]}, 'SP707627391517733135': {'261312': ['8619214', '5.43', '2022-11-01', True], '278271': ['8727917', '5.17', '2022-02-10', True]}, 'SP154552900631631962': {'261312': ['8618554', '22.74', '2022-11-01', True], '278271': ['8778617', '22.74', '2022-08-09', True]}, 'SP998793655916384187': {'261312': ['8633169', '0.00', '2', False]}, 'SP700044998249240859': {'261312': ['8618967', '10.02', '2022-11-01', True], '278271': ['8778541', '10.00', '2022-06-01', True]}, 'SP474547154881518434': {'261312': ['8802778', '0.00', '2', True]}, 'SP523821352939217793': {'261312': ['8618611', '0.00', '2', False]}, 'SP774558186501534746': {'261312': ['8802759', '0.00', '2', False]}, 'SP439286162349540704': {'261312': ['8781609', '0.00', '2', False]}, 'SP115993875598660285': {'261312': ['8653354', '33.80', '2022-12-05', True]}, 'SP699361327918574360': {'278271': ['8795083', '13.60', '2022-03-13', True], '261312': ['8618631', '13.60', '2022-06-11', True]}, 'SP856176483488326236': {'261312': ['8618216', '35.00', '2022-10-18', True]}, 'SP987061359765659605': {'261312': ['8616967', '94.47', '2', False], '278271': ['8794869', '94.50', '2021-04-25', False]}, 'SP994670884976124521': {'261312': ['8802793', '0.00', '2', True]}, 'SP268030537694465597': {'261312': ['8802791', '0.00', '2', True]}, 'SP478208272219864897': {'261312': ['8802761', '0.00', '2', True]}, 'SP281750222902738072': {'261312': ['8618662', '38.96', '2', False]}, 'SP745013244191056921': {'261312': ['8802790', '0.00', '2', True]}, 'SP248545274911927424': {'261312': ['8802776', '0.00', '2', True]}, 'SP424465070064716384': {'261312': ['8616871', '29.70', '2', False], '278271': ['8773860', '29.71', '2', False]}, 'SP921429205033012874': {'261312': ['8644684', '0.00', '2', False]}, 'SP918143438360030816': {'261312': ['8617258', '76.76', '2022-11-01', True]}, 'SP530858050221465010': {'261312': ['8617800', '28.42', '2', False]}, 'SP738885588167346513': {'261312': ['8618679', '9.20', '2', False]}, 'SP241199036050032574': {'278271': ['8752047', '64.90', '2022-07-06', True]}, 'SP214510114898633269': {'261312': ['8617940', '160.20', '2022-11-01', True]}, 'SP105500776069534402': {'261312': ['8617166', '106.28', '2', False]}, 'SP465704198199509776': {'278271': ['8727554', '5.70', '2022-05-13', True]}, 'SP716702409998380511': {'261312': ['8660606', '0.00', '2', False]}, 'SP442121585565014696': {'261312': ['8619120', '30.52', '2022-11-01', True], '278271': ['8795055', '33.94', '2021-12-25', True]}, 'SP415539275588149882': {'261312': ['8618350', '19.33', '2022-11-01', True], '278271': ['8778557', '19.14', '2022-07-22', True]}, 'SP766205220545093876': {'278271': ['8788703', '48.00', '2020-06-12', True], '261312': ['8619050', '48.00', '2022-11-01', True]}, 'SP365699875106370579': {'261312': ['8634217', '6.30', '2', False], '278271': ['8778741', '6.30', '2022-02-20', False]}, 'SP715081182195738511': {'261312': ['8634420', '6.30', '2', False]}, 'SP737099192051307797': {'261312': ['8619303', '28.53', '2', False]}, 'SP658255897335144296': {'278271': ['8727559', '4.22', '2', False]}, 'SP662935746919169932': {'278271': ['8788705', '12.60', '2', False], '261312': ['8618114', '12.60', '2', False]}, 'SP535388457793115492': {'261312': ['8802762', '0.00', '2', False]}, 'SP722550120252921006': {'261312': ['8617496', '7.85', '2022-11-05', True]}, 'SP188238191959030625': {'261312': ['8644663', '0.00', '2', False]}, 'SP142824499097026807': {'261312': ['8619513', '4.57', '2022-11-01', True]}, 'SP424141639058481232': {'278271': ['8727968', '5.28', '2', False]}, 'SP407949024296164571': {'261312': ['8802786', '0.00', '2', False]}, 'SP830395898789953859': {'261312': ['8619381', '7.99', '2022-11-01', True], '278271': ['8795068', '8.00', '2021-08-17', True]}, 'SP158984521598975341': {'261312': ['8618346', '36.90', '2', False]}, 'SP866152273193250786': {'261312': ['8637168', '22.07', '2', False]}, 'SP982557609358456594': {'261312': ['8619456', '90.71', '2', False]}, 'SP569426960226066400': {'261312': ['8653405', '269.00', '2022-12-05', True]}, 'SP407434842282674865': {'261312': ['8802785', '0.00', '2', True]}, 'SP797171849142001655': {'261312': ['8802773', '0.00', '2', False]}, 'SP338658217513546014': {'261312': ['8617195', '19.20', '2022-11-07', True], '278271': ['8778519', '14.49', '2022-06-27', True]}, 'SP922571684462910212': {'261312': ['8617657', '6.83', '2021-02-19', True]}, 'SP612021720051611019': {'261312': ['8802787', '0.00', '2', False]}, 'SP728424123471133456': {'261312': ['8619463', '6.70', '2', False]}, 'SP941390436025829323': {'261312': ['8619526', '4.00', '2', False]}, 'SP425611646306366806': {'261312': ['8618939', '20.04', '2022-11-01', True], '278271': ['8778595', '20.77', '2021-05-02', True]}, 'SP410378343690228894': {'261312': ['8619141', '8.00', '2022-11-05', True]}, 'SP237135355523307710': {'261312': ['8618414', '7.90', '2', False]}, 'SP583174914925323964': {'261312': ['8802788', '0.00', '2', False]}, 'SP306052198548187191': {'261312': ['8802783', '0.00', '2', False]}, 'SP707075511462393291': {'261312': ['8618437', '4.00', '2022-11-01', True], '278271': ['8751908', '3.97', '2022-05-27', True]}, 'SP214482385520239394': {'278271': ['8790321', '0.00', '2', False], '261312': ['8644654', '0.00', '2', False]}, 'SP956421130402153227': {'261312': ['8618084', '14.69', '2', False], '278271': ['8778502', '12.80', '2022-05-13', False]}, 'SP945779724001048936': {'261312': ['8618570', '5.30', '2022-09-27', True], '278271': ['8795038', '5.46', '2022-04-18', True]}, 'SP894783343542450173': {'278271': ['8788701', '97.19', '2', False]}, 'SP148855163778317944': {'278271': ['8773896', '82.53', '2022-05-31', True]}, 'SP884143455030275774': {'278271': ['8727748', '111.22', '2021-11-04', True]}, 'SP843684092191854367': {'261312': ['8617756', '261.00', '2022-11-01', True]}, 'SP631506692728349809': {'261312': ['8617606', '60.00', '2', False], '278271': ['8794958', '60.00', '2022-04-02', False]}, 'SP713188272500749486': {'261312': ['8802772', '0.00', '2', False]}, 'SP658312135705812179': {'261312': ['8802777', '0.00', '2', False]}, 'SP764032813921242028': {'261312': ['8618379', '33.31', '2022-11-01', True], '278271': ['8795175', '25.00', '2022-07-27', True]}, 'SP946993337131438362': {'261312': ['8802780', '0.00', '2', False]}, 'SP767162507942876684': {'261312': ['8617519', '1.54', '2022-11-05', True], '278271': ['8752001', '1.53', '2022-03-30', True]}, 'SP427786123354076814': {'278271': ['8794852', '14.39', '2022-06-07', True]}, 'SP195970733862418199': {'278271': ['8778646', '15.03', '2021-01-19', True], '261312': ['8616926', '18.04', '2022-11-01', True]}, 'SP384258684918339646': {'261312': ['8802766', '0.00', '2', True]}, 'SP599181453198450889': {'261312': ['8802796', '0.00', '2', False]}, 'SP209744011631827804': {'261312': ['8802792', '0.00', '2', False]}, 'SP213402646510430900': {'261312': ['8781607', '0.00', '2', False]}, 'SP488264609841139127': {'261312': ['8781608', '0.00', '2', False]}, 'SP852090214045757133': {'261312': ['8619056', '6.08', '2', False], '278271': ['8727885', '6.10', '2', False]}, 'SP769778601996140107': {'261312': ['8802760', '0.00', '2', False]}, 'SP112466934592380135': {'261312': ['8617650', '0.00', '2021-10-01', True]}, 'SP580627243850801840': {'261312': ['8802795', '0.00', '2', True]}, 'SP995174729414211953': {'278271': ['8727969', '7.00', '2', False]}, 'SP271840875840141717': {'261312': ['8781606', '0.00', '2', False]}, 'SP667959356850754623': {'278271': ['8727850', '2.40', '2', False]}, 'SP497955536980492879': {'278271': ['8727724', '4.35', '2', False]}, 'SP498176087254196244': {'261312': ['8618279', '5.46', '2', False], '278271': ['8773890', '5.44', '2', False]}, 'SP788171787727100995': {'261312': ['8802767', '0.00', '2', False]}, 'SP845543020659527070': {'278271': ['8778632', '10.02', '2022-05-13', False]}, 'SP759754595746801567': {'261312': ['8802784', '0.00', '2', True]}, 'SP702163147095077684': {'278271': ['8778554', '16.67', '2022-04-20', True]}, 'SP215892937669688957': {'278271': ['8795092', '18.50', '2022-06-04', False]}, 'SP355040735821858698': {'261312': ['8802774', '0.00', '2', False]}, 'SP257780504814775573': {'261312': ['8633668', '0.00', '2', True]}, 'SP140893702270209586': {'278271': ['8727812', '88.00', '2022-03-20', True]}, 'SP938090363827364252': {'261312': ['8619231', '56.05', '2', False]}, 'SP580762873033685770': {'261312': ['8619311', '47.01', '2022-11-01', True]}, 'SP136386969201917290': {'261312': ['8633904', '10.67', '2', False]}, 'SP870514578867272531': {'261312': ['8802789', '0.00', '2', False]}, 'SP825033967715417364': {'261312': ['8617253', '0.00', '2022-11-01', True]}, 'SP762732147699112286': {'278271': ['8727963', '9.90', '2022-08-14', False]}, 'SP502984898937653725': {'261312': ['8619103', '0.00', '2', False]}, 'SP594847097709960909': {'261312': ['8634163', '64.00', '2', False]}, 'SP205136958952755332': {'261312': ['8802768', '0.00', '2', True]}, 'SP731114593433349417': {'261312': ['8802775', '0.00', '2', True]}, 'SP235763366755878485': {'261312': ['8617327', '49.20', '2', False]}, 'SP217344982838879921': {'261312': ['8617711', '5.34', '2022-11-01', True]}, 'SP506008505626969271': {'261312': ['8618696', '71.10', '2', False]}, 'SP806780881788309202': {'261312': ['8802764', '0.00', '2', True]}, 'SP442158786094919926': {'261312': ['8633223', '0.00', '2', True]}, 'SP963370552497734692': {'278271': ['8778528', '14.50', '2', False]}, 'SP505694197334946372': {'261312': ['8618936', '125.00', '2022-10-18', True]}, 'SP253005868020762039': {'261312': ['8618753', '18.00', '2', False], '278271': ['8778702', '18.00', '2021-03-07', False]}, 'SP212944099727182359': {'278271': ['8778622', '4.05', '2', False]}, 'SP282695819287909022': {'261312': ['8672013', '0.00', '2', False]}, 'SP704559491352820561': {'278271': ['8727560', '30.38', '2022-06-26', True]}, 'SP410071559975103508': {'278271': ['8727639', '18.59', '2', False]}, 'SP861505289081407035': {'278271': ['8727693', '19.70', '2', False]}, 'SP154243759624299831': {'261312': ['8633744', '0.00', '2', True]}, 'SP984400576003783846': {'261312': ['8802782', '0.00', '2', False]}, 'SP786598043000128560': {'261312': ['8619387', '5.72', '2', False]}, 'SP360205237070323800': {'261312': ['8802770', '0.00', '2', False]}, 'SP426750374069326730': {'261312': ['8802779', '0.00', '2', True]}, 'SP969278437137867454': {'261312': ['8617204', '10.30', '2', False], '278271': ['8773905', '10.64', '2021-01-27', False]}, 'SP924313692816215003': {'261312': ['8634670', '0.00', '2', False]}, 'SP711088942414209237': {'261312': ['8617542', '5.31', '2', False]}, 'SP167057214654964182': {'261312': ['8617842', '10.40', '2', False]}, 'SP507271472067697000': {'261312': ['8619298', '10.40', '2', False]}, 'SP516473449760649869': {'261312': ['8781605', '0.00', '2', False]}, 'SP928929721992990049': {'278271': ['8751941', '13.70', '2022-07-02', True], '261312': ['8618444', '13.70', '2022-07-23', True]}, 'SP917288204422880139': {'278271': ['8751875', '13.70', '2022-07-08', True], '261312': ['8619012', '13.76', '2022-11-01', True]}, 'SP111425117457520180': {'261312': ['8618506', '8.71', '2', False]}, 'SP693705899232525801': {'261312': ['8617079', '97.90', '2', False], '278271': ['8794853', '97.90', '2022-03-04', False]}, 'SP853073229412285734': {'261312': ['8619377', '0.00', '2021-05-25', True]}, 'SP731863917845713944': {'261312': ['8633428', '0.00', '2', False]}}

inventories = []
sp_count =[]

for key_1,val_1 in in_list.items():#key_1 sp码, in_list[f'{ean_code}']  [f'{date}']  = [lot_data,total]
        for key,value in val_1.items():
            locationid = ''
            in_id = ''
            cost = ''
            currntquantity = ''
            for j,k in inventorylist[key_1].items():
                locationid = j #{'278271': ['8714909', '187.66', '2', False,20]}
                in_id = k[0]
                cost = k[1]
                currntquantity = k[4]
            producttime = key # 需要转换时间格式

            if key=='2':
                expectquantity = value[1]
            else:
                expectquantity = value[1]
            # 需要加一个 当数量一致的情况下 无须做库存调整
            if int(expectquantity) != int(currntquantity):
                dic = {'currentInventoryCost': f"{cost}", 'currentQuantity': f"{currntquantity}", 'expectedInventoryCost': f"{cost}",
                       'expectedQuantity': f"{expectquantity}", 'inventoryId': f"{in_id}"}
                inventories.append(dic)
                break
            else:
                print(key_1,expectquantity,currntquantity)

# 循环结束以后提交调整单
create = 'https://titan-api.xtw-tech.com/v1/adjustment_record/create'
header = {
    'authority': 'titan-api.xtw-tech.com',
    'method': 'POST',
    'path': '/v1/adjustment_record/create',
    'scheme': 'https',
    'accept': 'application/json, text/plain, */*',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'zh-CN,zh;q=0.9',
    'content-length': '342',
    'content-type': 'application/json',
    'grpc-metadata-application-code': 'MERCURY',
    'grpc-metadata-user-auth-token': f'{response_wms.cookies.values()[0]}',
    'origin': 'https://mercury.xtw-tech.com',
    'referer': 'https://mercury.xtw-tech.com/',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
}
dd = inventories
data = {'name': "岳阳中心仓库存调整1211-1", 'warehouseId': "741", 'inventories': dd, 'tenantId': "344"}
wjj = session_wms.post(json=data,headers=header,url=create)
print(wjj.json())


posted @ 2023-01-06 10:24  烦恼1234  阅读(3)  评论(0编辑  收藏  举报