46 lines
1.9 KiB
Python
Executable File
46 lines
1.9 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 = []
|
|
# 金蝶中 9000010400-A01 的所有出现
|
|
sub = kd[kd['code'] == '9000010400-A01']
|
|
out.append(f"=== 9000010400-A01 在金蝶中出现 {len(sub)} 次 ===")
|
|
for _, r in sub.iterrows():
|
|
out.append(f" 层级={r['lv']} 跳层={r['是否跳层']} BOM版本={r['BOM版本']}")
|
|
|
|
# 金蝶中 1.11.2 的直接子件数(层级以 1.11.2. 开头且无更深层)
|
|
direct = kd[kd['lv'].str.startswith('1.11.2.')]
|
|
# 直接子件 = 层级深度恰好比 1.11.2 多一级
|
|
def depth(lv): return len(lv.split('.'))
|
|
d112 = depth('1.11.2')
|
|
direct_children = direct[direct['lv'].apply(depth) == d112 + 1]
|
|
out.append(f"\n金蝶中 1.11.2 (9000010400-A01) 直接子件数: {len(direct_children)}")
|
|
|
|
# 数据库中 9000010400-A01 直接子件列表 vs 金蝶直接子件列表
|
|
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()
|
|
db_sub = set(db[db['parent'] == '9000010400-A01']['code'])
|
|
kd_sub = set(direct_children['code'])
|
|
|
|
only_db = sorted(db_sub - kd_sub)
|
|
only_kd = sorted(kd_sub - db_sub)
|
|
out.append(f"\n仅数据库有 ({len(only_db)}):")
|
|
for c in only_db:
|
|
nm = db[db['code'] == c]['MaterialName'].iloc[0] if len(db[db['code']==c])>0 else ''
|
|
out.append(f" {c} {nm}")
|
|
out.append(f"\n仅金蝶有 ({len(only_kd)}):")
|
|
for c in only_kd:
|
|
nm = kd[kd['code'] == c]['name'].iloc[0]
|
|
out.append(f" {c} {nm}")
|
|
|
|
with open('kd_10400.txt', 'w', encoding='utf-8') as f:
|
|
f.write('\n'.join(out))
|
|
print("done")
|