Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
amazon_reports
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
common
amazon_reports
Commits
ff1860dd
Commit
ff1860dd
authored
Jan 03, 2025
by
邱阿朋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加入库单处理及Excel数据处理功能
parent
bcecc30e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
25 deletions
+111
-25
easy_storage.exe
dist/easy_storage.exe
+0
-0
easy_storage.py
src/easy_storage.py
+109
-25
初始化.bat
初始化.bat
+2
-0
No files found.
dist/easy_storage.exe
0 → 100644
View file @
ff1860dd
File added
src/easy_storage.py
View file @
ff1860dd
# coding: utf-8
import
json
import
os
from
datetime
import
datetime
import
requests
import
xmltodict
import
pandas
as
pd
class
YcClient
:
...
...
@@ -20,7 +24,7 @@ class YcClient:
:param params_json: 请求的数据内容,Python 字典
:param service: 要调用的接口方法
:return: 响应内容
"""
"""
# 构造 SOAP 请求的 XML 数据
payload
=
f
"""<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.org/Ec/">
...
...
@@ -72,36 +76,116 @@ class YcClient:
return
cls
.
call_service
(
"getProductList"
,
params_json
)
@
classmethod
def
create_asn
(
cls
):
"""
创建入库单
"""
def
create_asn
(
cls
,
warehouse_code
,
desc
,
tracking_number
,
order_item_list
):
"""创建入库单"""
params_json
=
{
"reference_no"
:
"dfdfd1399866764"
,
"warehouse_code"
:
"HRBW"
,
"items"
:
[
{
"product_sku"
:
"EA140509201610"
,
"quantity"
:
10
,
"box_no"
:
1
,
}
]
"reference_no"
:
tracking_number
,
# 参考号
"warehouse_code"
:
warehouse_code
,
# 目的仓
"tracking_number"
:
tracking_number
,
# 跟踪号
"bulk_cargo_type"
:
1
,
# 散货类型(托)
"pallet_cnt"
:
1
,
# 散货托数量
"receiving_desc"
:
desc
,
# 描述
"items"
:
order_item_list
}
return
cls
.
call_service
(
"createAsn"
,
params_json
)
if
__name__
==
'__main__'
:
try
:
#
配置公共参数
class
Process
(
YcClient
)
:
def
__init__
(
self
)
:
#
调用 API
key
=
"c906cc46bda8cea593c0b6b20eadb1f2"
token
=
"2832175c4ee5c6efd79e129e919f2dfd"
super
()
.
__init__
(
key
,
token
)
@
classmethod
def
read_data
(
cls
,
file
):
# 读取 Excel 文件
result
=
pd
.
read_excel
(
file
)
# 按入库单跟踪号和 SKU 去重并汇总数量
result
=
result
.
groupby
([
'Shipment Request ID'
,
'SKU'
],
as_index
=
False
)
.
agg
({
'Return quantity'
:
'sum'
})
# 组装结果数据
result_list
=
{}
for
_
,
item
in
result
.
iterrows
():
tracking_number
=
item
.
get
(
'Shipment Request ID'
,
''
)
order_item
=
{
"product_sku"
:
item
.
get
(
'SKU'
,
''
),
"quantity"
:
item
.
get
(
'Return quantity'
,
0
),
"box_no"
:
1
}
# 初始化或追加数据
if
tracking_number
not
in
result_list
:
result_list
[
tracking_number
]
=
{
"item"
:
[]}
client
=
YcClient
(
key
,
token
)
resp
=
client
.
get_products
(
"KHD-CC-RF05-BLK"
)
for
item
in
resp
:
print
(
item
.
get
(
'product_title'
))
except
Exception
as
e
:
print
(
e
)
finally
:
print
(
"程序结束"
)
result_list
[
tracking_number
][
"item"
]
.
append
(
order_item
)
return
result_list
@
classmethod
def
send_data
(
cls
,
code
,
result_list
):
# 获取当前时间
desc
=
datetime
.
now
()
.
strftime
(
"
%
Y-
%
m"
)
result
=
{}
for
tracking_number
,
order_data
in
result_list
.
items
():
resp
=
cls
.
create_asn
(
code
,
desc
,
tracking_number
,
order_data
[
"item"
])
print
(
f
"跟踪号:{tracking_number}, 入库单号:{resp.get('receiving_code')}"
)
result
[
tracking_number
]
=
resp
.
get
(
'receiving_code'
)
return
result
@
classmethod
def
save_excel
(
cls
,
file
,
result
):
# 读取 Excel 文件
data
=
pd
.
read_excel
(
file
)
# 通过映射方式直接添加新列 'Receiving code'
data
[
'Receiving code'
]
=
data
[
'Shipment Request ID'
]
.
map
(
result
)
# 保存修改后的数据到原文件或另一个文件
output_file
=
file
.
replace
(
'.xlsx'
,
'_updated.xlsx'
)
data
.
to_excel
(
output_file
,
index
=
False
)
print
(
f
"结果已保存到 {output_file}"
)
# 仓库编码和名称的映射
warehouse_map
=
{
"USLAX01"
:
"美西CA仓库"
,
"KHDCN"
:
"国内仓-练习使用"
,
"USNJ01"
:
"美东NJ仓库"
,
"USWA03"
:
"Sumner仓"
,
"NOVILAND"
:
"Noviland"
,
"USHOU01"
:
"美南TX仓库"
,
"JPTOKYO01"
:
"日本关东仓库"
,
"CNFUJ01"
:
"CNFUJ01"
,
}
if
__name__
==
'__main__'
:
for
warehouse_code
,
warehouse_name
in
warehouse_map
.
items
():
print
(
f
"仓库编码:{warehouse_code} , 名称:{warehouse_name}"
)
while
True
:
# 提示用户输入
warehouse_code
=
input
(
"
\n
请输入仓库编码:"
)
.
strip
()
# 根据输入查找仓库名称
warehouse_name
=
warehouse_map
.
get
(
warehouse_code
)
if
warehouse_name
:
break
else
:
print
(
f
"仓库编码 [{warehouse_code}] 未找到对应的仓库名称,请重新输入。"
)
print
(
f
"
\n
仓库编码 [{warehouse_code}] 对应的仓库名称是:{warehouse_name}"
)
# 提示用户输入文件路径
file_path
=
input
(
"请输入 Excel 文件路径:"
)
.
strip
()
process
=
Process
()
# 处理文件
data_list
=
process
.
read_data
(
file_path
)
# 发送数据
send_result
=
process
.
send_data
(
warehouse_code
,
data_list
)
# 保存结果到 Excel 文件
process
.
save_excel
(
file_path
,
send_result
)
初始化.bat
View file @
ff1860dd
...
...
@@ -2,4 +2,5 @@ pip.exe install -i https://mirrors.cloud.tencent.com/pypi/simple -r requirements
pyinstaller -F -n payment.exe .\src\payment.py
pyinstaller -F -n return_goods.exe .\src\return_goods.py
pyinstaller -F -n spa_search.exe .\src\spa_search.py
pyinstaller -F -n easy_storage.exe .\src\easy_storage.py
pyinstaller -F -n diff_spa.exe .\cmd\diff_spa.py
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment