11111

# # xtw库存调整
# # 主要改进在于:尽可能将效期 录入到目标库位上。
# '''
#     无效期的 优先使用无效期批次的库存记录 (xjf-100-100 or 默认库位)
#     有效期:
#             优先使用带有修改批次的库存记录
#             次优先使用无效期批次的库存记录
# '''
# sheet ='data'
# import numpy as np
# import arrow
# import requests
# import pandas as pd
# from openpyxl import Workbook
#
#
# def time_to_utc(local):
#     time =arrow.get(local).to('local')
#     time_format = time.strftime('%Y-%m-%d')
#     return  time_format
#
# session_wms = requests.Session()
# info =()
# # 这个url是登陆入口
# login_url = "https://apollo-api.xtw-tech.com/v1/auth/token"
#
# # 请求头文件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)
# data = pd.read_excel('/Users/xujingfei/Desktop/收货信息/岳阳无到货单汇总验收上架.xlsx',engine='openpyxl',sheet_name='Sheet1')
#
# def wjj(ean_code,id):
#     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': "1"}],
#                                               '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']
#         if str(id) == str(sp_inventory_id):
#             snapshotQuantity = int(i['quantity'])
#             standardProductId = i['standardProductTenantMapping']['standardProduct']['id']
#             ownerid = i['owner']['id']
#             return [snapshotQuantity,ownerid,standardProductId]
#         else:
#             continue
#
#
#
# def lot(owner_id,productionTime,standardProductId):
#     lot_url = 'https://titan-api.xtw-tech.com/v1/lot/create'
#     header = {
#         '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-languagev': 'zh-CN,zh;q=0.9',
#         'content-length': '125',
#         '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',
#     }
#     pa = {'ownerId': f"{owner_id}", 'productionTime': f"{productionTime}",
#           'standardProductId': f"{standardProductId}", 'tenantId': "344",
#           'warehouseId': "741"}
#
#     mm = session_wms.post(url=lot_url, headers=header, json=pa)
#     lotId = mm.json()['lot']['id']
#     return lotId
#
# def time_to_utc(localtime):
#     utctime =arrow.get(localtime).to('UTC')
#     utc_time_format = utctime.strftime('%Y-%m-%dT%H:%M:%SZ')
#     return  utc_time_format
#
#
# for i in range(len(data.index)):
#     sp = data.iloc[i,0]
#     datetime = time_to_utc(data.iloc[i,1])
#     quantity = data.iloc[i,4]
#     id = data.iloc[i,8]
#     locationId = data.iloc[i,2]
#     result = wjj(sp,id) # [snapshotQuantity,ownerid,standardProductId]
#     snapshotQuantity = result[0] # 将lotid需要的 owner 以及 standardProductId 、owner_id 一块返回。
#     ownerid = result[1]
#     standardProductId = result[2]
#     LotId = lot(owner_id=ownerid,productionTime=datetime,standardProductId=standardProductId) # lot(owner_id,productionTime,standardProductId)
#
#     url = f'https://titan-api.xtw-tech.com/v1/inventory/by_id/{id}/update_initialize_lot'
#     header ={
#         'authority': 'titan-api.xtw-tech.com',
#         'method': 'POST',
#         'path': f'/v1/inventory/by_id/{id}/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': '92',
#         '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',
#     }
#
#     da = {'snapshotQuantity': f"{snapshotQuantity}", 'items': [{'LotId': f"{LotId}", 'quantity': f"{quantity}", 'locationId': f"{locationId}"}]}
#     kk = session_wms.post(url=url,headers=header,json=da)
#     if kk.status_code !=200:
#         print(sp,kk.json())
#     else:
#         pass


# xtw库存调整
# 主要改进在于:尽可能将效期 录入到目标库位上。
'''
    无效期的 优先使用无效期批次的库存记录 (xjf-100-100 or 默认库位)
    有效期:
            优先使用带有修改批次的库存记录
            次优先使用无效期批次的库存记录
'''
sheet ='data'
import numpy as np
import arrow
import requests
import pandas as pd
from openpyxl import Workbook


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

session_wms = requests.Session()
info =()
# 这个url是登陆入口
login_url = "https://apollo-api.xtw-tech.com/v1/auth/token"

# 请求头文件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)
data = pd.read_excel('/Users/xujingfei/Desktop/收货信息/岳阳无到货单汇总验收上架.xlsx',engine='openpyxl',sheet_name='Sheet1')

def wjj(ean_code,id):
    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': "1"}],
                                              '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']
        if str(id) == str(sp_inventory_id) :
            snapshotQuantity = int(i['quantity'])
            standardProductId = i['standardProductTenantMapping']['standardProduct']['id']
            ownerid = i['owner']['id']
            return [snapshotQuantity,ownerid,standardProductId]
        else:
            continue



def lot(owner_id,productionTime,standardProductId):
    lot_url = 'https://titan-api.xtw-tech.com/v1/lot/create'
    header = {
        '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-languagev': 'zh-CN,zh;q=0.9',
        'content-length': '125',
        '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',
    }
    pa = {'ownerId': f"{owner_id}", 'productionTime': f"{productionTime}",
          'standardProductId': f"{standardProductId}", 'tenantId': "344",
          'warehouseId': "741"}

    mm = session_wms.post(url=lot_url, headers=header, json=pa)
    lotId = mm.json()['lot']['id']
    return lotId

def time_to_utc(localtime):
    utctime =arrow.get(localtime).to('UTC')
    utc_time_format = utctime.strftime('%Y-%m-%dT%H:%M:%SZ')
    return  utc_time_format


for i in range(len(data.index)):
    sp = data.iloc[i,0]
    datetime = time_to_utc(data.iloc[i,1])
    quantity = data.iloc[i,4]
    id = data.iloc[i,8]
    locationId = data.iloc[i,2]
    result = wjj(sp,id) # [snapshotQuantity,ownerid,standardProductId]
    snapshotQuantity = result[0] # 将lotid需要的 owner 以及 standardProductId 、owner_id 一块返回。
    ownerid = result[1]
    standardProductId = result[2]
    LotId = lot(owner_id=ownerid,productionTime=datetime,standardProductId=standardProductId) # lot(owner_id,productionTime,standardProductId)

    url = f'https://titan-api.xtw-tech.com/v1/inventory/by_id/{id}/update_initialize_lot'
    header ={
        'authority': 'titan-api.xtw-tech.com',
        'method': 'POST',
        'path': f'/v1/inventory/by_id/{id}/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': '92',
        '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',
    }

    da = {'snapshotQuantity': f"{snapshotQuantity}", 'items': [{'LotId': f"{LotId}", 'quantity': f"{quantity}", 'locationId': f"{locationId}"}]}
    kk = session_wms.post(url=url,headers=header,json=da)
    if kk.status_code !=200:
        print(sp,datetime,locationId,kk.json())
    else:
        pass


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