打印发货单明细


# @author xjf
# 用途:打印发货单明细

import requests
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
# title = ['发货仓','订单类型','发货单号','发货单号状态','SP','库存类型','品名','数量','客户名','下单地址','订单号']
title = ['发货仓','订单类型','发货单号','发货单号状态','SP','品名','数量']
ws.append(title)
# 打印发货单及明细
session_wms = requests.Session()
# 这个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 = {

    }


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


solist ='https://titan-api.xtw-tech.com/v1/shipment_order/list'
header ={
    'authority': 'titan-api.xtw-tech.com',
    'method': 'POST',
    'path': '/v1/shipment_order/list',
    'scheme': 'https',
    'accept': 'application/json, text/plain, */*',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'zh-CN,zh;q=0.9',
    'content-length': '295',
    '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',
}
# tenantIds= ['1','344','103','1']
# warehouse_ids =['137','741','268','96']

tenantIds= ['1']
warehouse_ids =['137']

for tenantId,warehouse_id in zip(tenantIds,warehouse_ids):
# for tenantId in tenantIds:
    for page in range(1):
        data = {'tenantId': f"{tenantId}", 'justShowMine': False, 'listOption': {'keyword': "", 'page': f'{page+1}', 'pageSize': '100',
                                                                       'fieldFilter': [{'fieldToFilter': "show_crossowner",
                                                                                        'keyword': "false"}
                                                                                       {'fieldToFilter': "status_list",
                                                                                        'keyword':"201,300,302,303,403,500,600"},
                                                                                       {'fieldToFilter': "warehouse_ids",
                                                                                        'keyword': f"{warehouse_id}"},{'fieldToFilter': "created_time_start", 'keyword': "2022-11-29T00:00:00+08:00"},
                                                                                       {'fieldToFilter': "created_time_end", 'keyword': "2030-11-30T23:59:59+08:00"}]}
                }
        # data = {'tenantId': f"{tenantId}", 'justShowMine': True, 'listOption': {'keyword': "", 'page': f'{page+1}', 'pageSize': '100',
        #                                                                'fieldFilter': [{'fieldToFilter': "show_crossowner",
        #                                                                                 'keyword': "false"}, {'fieldToFilter': "serial_number", 'keyword': "SO-20221201-9885660153"}]}
        #         }
        response = session_wms.post(headers=header,url=solist,json=data)
        item =  response.json()['items']
        for i in item:
            name = i['consigneeInfo']['name']
            poiAddress = i['consigneeInfo']['poiAddress']
            relatedSerialNumber = i['relatedSerialNumber']
            status = i['status']
            type =i['type']
            serialNumber =i['serialNumber']
            warehouse =i['warehouse']['name']

            so_url = f'https://titan-api.xtw-tech.com/v1/shipment_order/by_serial_number/{serialNumber}?tenantId={tenantId}'
            header ={
                'authority': 'titan-api.xtw-tech.com',
                'method': 'GET',
                'path': f'/v1/shipment_order/by_serial_number/{serialNumber}?tenantId={tenantId}',
                'scheme': 'https',
                'accept': 'application/json, text/plain, */*',
                'accept-encoding': 'gzip, deflate, br',
                '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',
            }
            deatil = session_wms.get(url=so_url,headers=header)
            req = deatil.json()
            shipmentOrderWithDetail = req['shipmentOrderWithDetail']['inventories']
            for sp in shipmentOrderWithDetail:
                # ['发货仓','订单号','发货单号','发货单号状态','SP','品名','效期状态','数量','收货人','收货地址']
                sieveName = sp['sieveName'] # 有效期
                code = sp['standardProductTenantMapping']['standardProduct']['code']
                sp_name = sp['standardProductTenantMapping']['standardProduct']['name']
                expectedQuantity = sp['expectedQuantity']
                # info = (warehouse,type,serialNumber,status,code,sp_name,sieveName,expectedQuantity,name,poiAddress,relatedSerialNumber)
                info = (warehouse, type, serialNumber, status, code, sp_name, expectedQuantity)
                ws.append(info)
wb.save('G:/0310/订单9885660153.xlsx')
posted @ 2022-12-02 18:34  烦恼1234  阅读(35)  评论(0编辑  收藏  举报