Files
star 7d34a481b3 feat: 库存管理系统 MaterialWMS 初始版本
- Flask + SQLAlchemy 物料/入库/出库/BOM/生产订单全模块管理
- PyInstaller 打包为单文件 EXE (双击运行, 自动建库)
- 物料维度: 入库总数量 / 消耗总数量 / 逐次入库流水(含时间)
- BOM 详情展示组成物料的规格型号与单套用量
- 支持 Altium / 嘉立创 BOM 批量导入(文本与 Excel 双通道)
- 内置端到端验证脚本(tools/_exe_util.py 等, 清理进程树防残留)
2026-09-11 15:41:56 +08:00

66 lines
2.2 KiB
Python

"""验证打包后的 EXE: 等端口 -> 登录 -> 访问关键页面 -> Excel 导出
用法: 先手动启动 dist/MaterialWMS.exe, 再 python tools/check_exe.py
"""
import sys, time, urllib.request, urllib.parse
BASE = "http://127.0.0.1:8080"
def wait_port(t=40):
for i in range(t):
try:
urllib.request.urlopen(BASE + "/login", timeout=2)
return True
except Exception:
time.sleep(1)
return False
def get(path, cookie=None):
req = urllib.request.Request(BASE + path)
if cookie:
req.add_header("Cookie", cookie)
return urllib.request.urlopen(req, timeout=5)
def post(path, data, cookie=None):
req = urllib.request.Request(BASE + path, data=urllib.parse.urlencode(data).encode(), method="POST")
if cookie:
req.add_header("Cookie", cookie)
return urllib.request.urlopen(req, timeout=5)
def main():
if not wait_port():
print("[FAIL] 端口 8080 未就绪 (EXE 可能未启动或解压慢)")
sys.exit(1)
print("[OK] EXE 服务已就绪")
# 登录页
r = get("/login")
assert "登录" in r.read().decode("utf-8", "ignore")
print("[OK] 登录页(冻结模板加载正常)")
# 登录
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor())
req = urllib.request.Request(BASE + "/login",
data=urllib.parse.urlencode({"username": "admin", "password": "admin123"}).encode(),
method="POST")
resp = opener.open(req)
body = resp.read().decode("utf-8", "ignore")
assert "库存看板" in body, "登录后未进入看板"
print("[OK] 管理员登录成功, 看板渲染正常")
# 关键页面(冻结模板 + 路由)
for p in ["/boms", "/orders", "/report", "/logs", "/users", "/import/materials", "/template/bom"]:
rr = opener.open(BASE + p)
assert rr.status == 200
print("[OK] BOM/订单/报表/日志/用户/导入/模板 页面均可访问")
# 导出 Excel
rr = opener.open(BASE + "/export/inventory")
data = rr.read()
assert rr.status == 200 and len(data) > 1000
print(f"[OK] 库存 Excel 导出成功 ({len(data)} 字节)")
print("\nEXE 端到端验证通过 ✅")
if __name__ == "__main__":
main()