1111

# xtw库存调整
# 主要改进在于:尽可能将效期 录入到目标库位上。
'''
    无效期的 优先使用无效期批次的库存记录 (xjf-100-100 or 默认库位)
    有效期:
            优先使用带有修改批次的库存记录
            次优先使用无效期批次的库存记录
'''
sheet ='data'
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','目标库位库存'  ,'合计库存']
# 17:33
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_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/岳阳无到货单汇总验收上架.xlsx',sheet_name=f'{sheet}',engine='openpyxl')
# # 需要改变遍历方式
# 用于存储sp在该仓库的库位上的库存记录情况
# adjust_data['date'] = np.where(adjust_data['生产日期'].isna(),'2',time_trans(adjust_data['生产日期']))
# adjust_data.loc[:,['sp','生产日期','total','sp效期合计数量']].drop_duplicates(inplace=True)

def initialize(sp):
    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': '96',
        '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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
    }
    data = {'spCodeList': [sp], 'ownerId': "1", 'warehouseIdList': ["741"], 'tenantId': "344"}
    result1 =session_wms.post(url=url,headers=header,json=data)
    result = result1.json()
    return [result,result1.status_code]

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']
    if  item:
        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
        # 尝试库存初始化
    else:
        result = initialize(sp)
        if result[1]==200:
            start(sp)
            return 200
        else:
            print(f'请确认该{sp}是否正确')


def adjust(sp):
    inventorylist = {}
    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': "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'{sp}'] ={}
    price = 0.00
    for i in item:
        sp_inventory_id = i['id']
        if price<= float(i['inventoryCost']):
            price = float(i['inventoryCost']) # 改进点:价格去非0的价格
        currentQuantity = int(i['quantity'])
        inventoryId = i['location']['id']
        sp = i['standardProductTenantMapping']['standardProduct']['code']
        lotEnabled = i['lotEnabled']
        try:
            productionTime = time_to_utc(i['lot']['productionTime'])
        except:
            productionTime='2'
        inventorylist[f'{sp}'][sp_inventory_id]=[price,currentQuantity,inventoryId,lotEnabled,productionTime,i['inventoryCost']]
        # 意味着 inventorylist[f'{sp}'][-1:] 的price为该sp在该仓库最大的价格

    return inventorylist




#用于存储sp在目标库位上的目标库存
in_list ={}
inventories = []

for i in range(len(adjust_data.index)):
    id = adjust_data.iloc[i, :11]
    sp = id.at['sp']
    number = id.at['良品数量']
    date = id.at['生产日期']  # 无效期的需要填充为2
    goallocid = id.at['库位id']
    print(sp,date)
    #只所以没有现在带上库位,启用非xjf 、默认库位的一定是带有效期的库存可以通过效期修改批次 直接移库过去。
    total=  id.at['total']  # 没有效期需要调整的库存数量
    lot_data = id.at['sp效期合计数量'] # 带有效期需要调整的库存数量
    if sp in in_list.keys():
        in_list[f'{sp}'][f'{date}']  = [lot_data,total]
    else:
        in_list[f'{sp}'] ={}
        in_list[f'{sp}'][f'{date}']  = [lot_data,total]

    inventorylist = adjust(sp) # 返回sp在该库存的记录
    for key,value in inventorylist.items():#库存库位启用
        if value=={}:
            k=  start(key)
            if k !=200:
                print(key,k)

    inventorylist = adjust(sp)
    inventorylist1 = inventorylist[f'{sp}']
    df =pd.DataFrame.from_dict(inventorylist1,orient='index',columns=['price','currentQuantity','inventoryId','lotEnabled','productionTime','currentcost'])
    df.sort_values(['lotEnabled', 'productionTime'],ascending=[False,True],inplace=True)


    # 无效期的 优先使用无效期批次的库存记录 (xjf-100-100 or 默认库位)
    # 有库存记录以后 如何选择
    # 主要改进在于:尽可能将效期 录入到目标库位上。
    # 有效期:
    # 优先使用带有修改批次的库存记录
    # 次优先使用无效期批次的库存记录
    if str(date)!='2':# 说明是带有效期
        #优先lotEnabled为true,带生产日期,库位id是目标库位
        t1 = df[(df['inventoryId']==str(goallocid))&(df['lotEnabled']==True)&(df['productionTime']!='2')]
        t2 = df[(df['inventoryId']!=str(goallocid))&(df['lotEnabled']==True)&(df['productionTime']!='2')]
        t3 = df[(df['inventoryId'].str.contains('278271|261312'))&(df['lotEnabled']==False)&(df['productionTime']=='2')]
        t = ''
        if not t1.empty:
            t = t1
            currentQuantity = t.iloc[0,1]
            expectedQuantity = lot_data+int(currentQuantity)
            dic = {'currentInventoryCost': f"{t.iloc[0,5]}", 'currentQuantity': f"{currentQuantity}", 'expectedInventoryCost': f"{t.iloc[0,0]}",
                   'expectedQuantity': f"{expectedQuantity}", 'inventoryId': f"{t.index.to_list()[0]}"}
            inventories.append(dic)
            continue
        elif not t2.empty:
            t = t2
            currentQuantity = t.iloc[0,1]
            expectedQuantity = lot_data+int(currentQuantity)
            dic = {'currentInventoryCost': f"{t.iloc[0,5]}", 'currentQuantity': f"{currentQuantity}", 'expectedInventoryCost': f"{t.iloc[0,0]}",
                   'expectedQuantity': f"{expectedQuantity}", 'inventoryId': f"{t.index.to_list()[0]}"}
            inventories.append(dic)
            continue

        elif not t3.empty:
            t = t3
            currentQuantity = t.iloc[0,1]
            expectedQuantity = total+int(currentQuantity)
            dic = {'currentInventoryCost': f"{t.iloc[0,5]}", 'currentQuantity': f"{currentQuantity}", 'expectedInventoryCost': f"{t.iloc[0,0]}",
                   'expectedQuantity': f"{expectedQuantity}", 'inventoryId': f"{t.index.to_list()[0]}"}
            inventories.append(dic)
            continue


            # dic = {'currentInventoryCost': f"{t.iloc[0,0]}", 'currentQuantity': f"{currentQuantity}", 'expectedInventoryCost': f"{t.iloc[0,0]}",
            #                        'expectedQuantity': f"{total}", 'inventoryId': f"{t.iloc[0,]}"}
            # inventories.append(dic)
        # 优先lotEnabled为true,带生产日期 库位为其他库位

        # 次lotEnabled为false,且不带生产日期的xjf-100-100 or 默认库位,这一部分无法录入效期。
        pass


    else:#说明不带效期
        #直接在目标库位调整
        t1 = df[(df['inventoryId']==str(goallocid))&(df['lotEnabled']==False)&(df['productionTime']=='2')]
        t2 = df[(df['inventoryId']=='278271')&(df['lotEnabled']==False)&(df['productionTime']=='2')]
        t3 = df[(df['inventoryId']=='261312')&(df['lotEnabled']==False)&(df['productionTime']=='2')]
        t  = ''
        if not t1.empty:
            t = t1
            currentQuantity = t.iloc[0,1]
            expectedQuantity = number+int(currentQuantity)
            dic = {'currentInventoryCost': f"{t.iloc[0,5]}", 'currentQuantity': f"{currentQuantity}", 'expectedInventoryCost': f"{t.iloc[0,0]}",
               'expectedQuantity': f"{expectedQuantity}", 'inventoryId': f"{t.index.to_list()[0]}"}
            inventories.append(dic)
            continue
        elif not t2.empty:

            t = t2
            currentQuantity = t.iloc[0,1]
            expectedQuantity = total+int(currentQuantity)
            dic = {'currentInventoryCost': f"{t.iloc[0,5]}", 'currentQuantity': f"{currentQuantity}", 'expectedInventoryCost': f"{t.iloc[0,0]}",
                   'expectedQuantity': f"{expectedQuantity}", 'inventoryId': f"{t.index.to_list()[0]}"}
            inventories.append(dic)
            continue
        elif not t3.empty:
            t = t3
            currentQuantity = t.iloc[0,1]
            expectedQuantity = total+int(currentQuantity)
            dic = {'currentInventoryCost': f"{t.iloc[0,5]}", 'currentQuantity': f"{currentQuantity}", 'expectedInventoryCost': f"{t.iloc[0,0]}",
                   'expectedQuantity': f"{expectedQuantity}", 'inventoryId': f"{t.index.to_list()[0]}"}
            inventories.append(dic)
            continue




        # xjf-100-100 or 默认库位


    # for keys,values in inventorylist[f'{sp}'].items():
    #     idEnd = list(inventorylist[f'{sp}'].keys())[-1]
    #     cost = inventorylist[f'{sp}'][idEnd][0]
    #     productionTime = values[4]
    #     lotEnabled = values[3]
    #
    # # 确认使用哪一个inventoryID 进行库存调整
    #     if str(date)!='2':# 说明是带有效期
    #         # inventorylist[f'{sp}'][sp_inventory_id]=[price,currentQuantity,inventoryId,lotEnabled,productionTime]
    #         if keys not in ['278271','261312']: #先排除掉这两个库位上的库存记录:
    #             if lotEnabled==True and productionTime!='2':# 使用带有效期的库存记录
    #                 currentQuantity = values[1]
    #                 dic = {'currentInventoryCost': f"{values[0]}", 'currentQuantity': f"{currentQuantity}", 'expectedInventoryCost': f"{cost}",
    #                        'expectedQuantity': f"{total}", 'inventoryId': f"{keys}"}
    #                 inventories.append(dic)
    #                 break
    #             else: # 这里要打一个问号?
    #                 continue
    #         else:
    #             t =  df[(df['inventoryId']=='278271')& (df['productionTime']=='2')]
    #             if t:
    #                 currentQuantity = t.iloc[0,1]
    #                 currentInventoryCost = t.iloc[0,0]
    #                 #         # 如何 将库存id也一块保存下来呢
    #                 dic = {'currentInventoryCost': f"{currentInventoryCost}", 'currentQuantity': f"{currentQuantity}", 'expectedInventoryCost': f"{currentInventoryCost}",
    #                        'expectedQuantity': f"{total}", 'inventoryId': '278271'}
    #                 inventories.append(dic)
    #                 break
    #             # else:# 说明在278271库位下没有库存
    #             elif '261312' in inventorylist[f'{sp}'].keys() and inventorylist[f'{sp}']['261312'][4] =='2':
    #                     currentQuantity = inventorylist[f'{sp}']['261312'][1]
    #                     dic = {'currentInventoryCost': f"{values[0]}", 'currentQuantity': f"{currentQuantity}", 'expectedInventoryCost': f"{cost}",
    #                            'expectedQuantity': f"{total}", 'inventoryId': f"{keys}"}
    #                     inventories.append(dic)
    #                     break
    #             elif '278271' in inventorylist[f'{sp}'].keys() or '261312' in inventorylist[f'{sp}'].keys():
    #                 print(f"该{sp}要启用带有效期的【'278271','261312'】")
    #             else:
    #                 continue
    #
    #     else: # 说明不带效期 ,不从其他库位调整库位
    #          # 存在库存记录更新
    #             if productionTime=='2':
    #                 for i in list(inventorylist[f'{sp}'].values()):
    #                     if goallocid == i[2] and i[4]=='2':
    #                         dic = {'currentInventoryCost': f"{i[0]}", 'currentQuantity': f"{i[1]}", 'expectedInventoryCost': f"{i[0]}",
    #                                'expectedQuantity': f"{total}", 'inventoryId': f"{keys}"}
    #                         inventories.append(dic)
    #                         break
    #
    #                 if goallocid in list(inventorylist[f'{sp}'].values())[0]:
    #                     currentQuantity = list(inventorylist[f'{sp}'].values())[0][1]
    #                     dic = {'currentInventoryCost': f"{values[0]}", 'currentQuantity': f"{currentQuantity}", 'expectedInventoryCost': f"{cost}",
    #                            'expectedQuantity': f"{total}", 'inventoryId': f"{keys}"}
    #                     inventories.append(dic)
    #                     break
    #
    #                 if '278271' in list(inventorylist[f'{sp}'].values())[0]:
    #                     currentQuantity = list(inventorylist[f'{sp}'].values())[0][1]
    #             #         # 如何 将库存id也一块保存下来呢
    #                     dic = {'currentInventoryCost': f"{values[0]}", 'currentQuantity': f"{currentQuantity}", 'expectedInventoryCost': f"{cost}",
    #                    'expectedQuantity': f"{total}", 'inventoryId': f"{keys}"}
    #                     inventories.append(dic)
    #                     break
    #                 else:# 说明在278271库位下没有库存
    #                     if '261312' in list(inventorylist[f'{sp}'].values())[0]:
    #                         currentQuantity = list(inventorylist[f'{sp}'].values())[0][1]
    #
    #                         dic = {'currentInventoryCost': f"{values[0]}", 'currentQuantity': f"{currentQuantity}", 'expectedInventoryCost': f"{cost}",
    #                                'expectedQuantity': f"{total}", 'inventoryId': f"{keys}"}
    #                         inventories.append(dic)
    #                         break
    #             if productionTime!='2':# 说明无奈只能使用带有效期的'278271' or '261312' 库存记录了。
    #                 print(f"说明{sp}无奈只能使用带有效期的'278271' or '261312' 库存记录了。")

'''
# 修改效期
url = 'https://titan-api.xtw-tech.com/v1/lot/create'
header ={
    access-control-allow-origin: https://mercury.xtw-tech.com
    content-encoding: gzip
    content-type: application/json
    date: Fri, 30 Dec 2022 16:00:34 GMT
    grpc-metadata-content-type: application/grpc
    grpc-metadata-grpc-accept-encoding: identity, deflate, gzip
    strict-transport-security: max-age=15724800; includeSubDomains
    vary: Accept-Encoding
    :authority: titan-api.xtw-tech.com
    :method: POST
    :path: /v1/lot/create
    :scheme: https
    accept: application/json, text/plain, */*
    accept-encoding: gzip, deflate, br
    accept-language: zh-CN,zh;q=0.9
    content-length: 125
    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: "Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"
    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/108.0.0.0 Safari/537.36
}

data ={
{tenantId: "344", warehouseId: "741", ownerId: "1",
standardProductId: "455364",productionTime: "2022-12-29T16:00:09.472Z",standardProductId: "455364"}
}

URL= https://titan-api.xtw-tech.com/v1/inventory/by_id/8773904/update_initialize_lot
headr ={
:authority: titan-api.xtw-tech.com
:method: POST
:path: /v1/inventory/by_id/8773904/update_initialize_lot
:scheme: https
accept: application/json, text/plain, */*
accept-encoding: gzip, deflate, br
accept-language: zh-CN,zh;q=0.9
content-length: 90
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: "Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"
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/108.0.0.0 Safari/537.36}
data ={snapshotQuantity: "1", items: [{LotId: "473341", quantity: "1", locationId: "261312"}]}

'''



# 循环结束以后提交调整单
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
print(dd)
data = {'name': "岳阳中心仓库存调整1213", 'warehouseId': "741", 'inventories': dd, 'tenantId': "344"}
wjj = session_wms.post(json=data,headers=header,url=create)
print(wjj.json())



posted @ 2023-01-04 10:41  烦恼1234  阅读(4)  评论(0编辑  收藏  举报