抓取生产工单,抓取发料异常

This commit is contained in:
hjq
2026-06-11 17:51:01 +08:00
parent 5b19790037
commit a160d5d48f
12 changed files with 965 additions and 58 deletions

View File

@@ -100,10 +100,13 @@ def fetch_bom_cost_tree():
data = body if isinstance(body, (dict, list)) else json.loads(body)
if isinstance(data, dict) and "result" in data:
items = data["result"].get("items", [])
total_records = data["result"].get("totalCount", 0)
result_data = data.get("result") or {}
items = result_data.get("items", [])
total_records = result_data.get("totalCount", 0)
for item in items:
if not item:
continue
# 注意:我们要拿的是 parentMaterialId因为这是传给 BOM 成本 API 的关键参数 materialId
clean_parent = {
"_id": item.get("id"), # 这个是 partBomCostAccountingId
@@ -237,7 +240,12 @@ def fetch_bom_cost_tree():
log("ERR", f"❌ 自动触发入库脚本失败: {db_err}")
except Exception as e:
log("ERR", f"发生异常: {e}")
import traceback
err_msg = f"发生异常: {e}\n{traceback.format_exc()}"
with open("error.log", "w") as f:
f.write(err_msg)
print(err_msg, flush=True)
log("ERR", err_msg)
if __name__ == "__main__":
fetch_bom_cost_tree()