Files
GX.O3.WMS/WebApi/docs/check_3420_bom.py
T

36 lines
1.4 KiB
Python
Executable File

# -*- coding: utf-8 -*-
import pandas as pd
kd = pd.read_excel('物料清单正查_1.xlsx', sheet_name='树形单据体')
kd = kd[kd['子项物料编码'].notna()].copy()
kd['code'] = kd['子项物料编码'].astype(str).str.strip()
kd['name'] = kd['物料名称'].astype(str).str.strip()
kd['lv'] = kd['BOM层级'].astype(str).str.strip()
out = []
# 金蝶中 1.11.2 的所有后代(含深层),看有没有 3420 的子件被"跳层"展开
desc = kd[kd['lv'].apply(lambda x: x.startswith('1.11.2.'))]
out.append(f"1.11.2 后代总数: {len(desc)}")
# 深度分布
from collections import Counter
dc = Counter(len(lv.split('.')) for lv in desc['lv'])
out.append(f"深度分布: {dict(sorted(dc.items()))}")
# 数据库中 9000013420-A01 的4个子件,在金蝶 1.11.2 子树里是否存在
db = pd.read_csv('db_bom2.csv', dtype=str)
db['code'] = db['ChildMaterialId'].astype(str).str.strip()
db['parent'] = db['ParentMaterialId'].astype(str).str.strip()
kids3420 = db[db['parent'] == '9000013420-A01']['code'].tolist()
out.append(f"\n数据库 9000013420-A01 子件: {kids3420}")
for c in kids3420:
hit = kd[kd['code'] == c]
if len(hit) == 0:
out.append(f" {c}: 金蝶整个文件不存在")
else:
for _, r in hit.iterrows():
out.append(f" {c}: 金蝶出现于 层级={r['lv']}")
with open('kd_3420.txt', 'w', encoding='utf-8') as f:
f.write('\n'.join(out))
print("done")