feat: 成本核算模块(鲁铭成本核算Excel全量适配, 价格库580条+75/85/95三系列模板+估算器基准精确还原)
- 解析12表成本核算工作簿: 价格库8表→产品价格本(华健型材模具/丝吉利娅/索宾柯五金/隔热条/胶条/赛遨辅材/螺丝/其他) - 「铝成本」页→系列成本模板(75框扇齐平1.4/85框扇齐平1.8/95窗纱一体1.8, 八分区JSON) - 估算器口径对齐核算表: 固定/开启/总面积归因缩放+人工每平实际口径+毛利阶梯10%~70% - 75系列基准估算total=1118.20与核算表成本合计完全一致(85/95同) - API /api/costbook: import-excel/series/estimate; 前端 /cost_estimate 页 - 种子 seed_costbook.py; 修复6处解析缺陷; 冒烟60/60+24页巡检0异常+深度审计16/16
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""成本核算数据种子:解析 data/ 下三个鲁铭系列成本核算 Excel,全量导入价格库与系列模板。
|
||||
|
||||
用法: uv run python -m huamenchuang.scripts.seed_costbook [--company 1]
|
||||
"""
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
DATA = Path(__file__).resolve().parents[3] / "data"
|
||||
FILES = [
|
||||
"3.2成本核算鲁铭75框扇齐平系列1.4.xlsx",
|
||||
"3.2成本核算鲁铭85框扇齐平系列1.8.xlsx",
|
||||
"2026.7.28成本核算鲁铭95窗纱一体系列1.8.xlsx",
|
||||
]
|
||||
|
||||
|
||||
async def seed(company_id: int = 1) -> None:
|
||||
import huamenchuang.models # noqa: F401
|
||||
from huamenchuang.core.database import SessionLocal, init_db
|
||||
from huamenchuang.services import costbook_service as svc
|
||||
|
||||
await init_db()
|
||||
async with SessionLocal() as db:
|
||||
lib_stats = {"created": 0, "updated": 0}
|
||||
series_ids = []
|
||||
for fn in FILES:
|
||||
path = DATA / fn
|
||||
if not path.exists():
|
||||
print(f"跳过(不存在): {fn}")
|
||||
continue
|
||||
parsed = svc.parse_costbook(path)
|
||||
stats = await svc.import_libraries(db, company_id, parsed["libraries"])
|
||||
tid = await svc.import_series(db, company_id, parsed)
|
||||
series_ids.append((tid, parsed["series_summary"]["window"].get("series"),
|
||||
parsed["file"]))
|
||||
lib_stats["created"] += stats["created"]
|
||||
lib_stats["updated"] += stats["updated"]
|
||||
opt = parsed["optimize_stats"]
|
||||
print(f"[{fn}] 系列{parsed['series_summary']['window'].get('series')} "
|
||||
f"型材{len(parsed['series_summary']['profile'])}行 优化单{opt.get('bars', 0)}支")
|
||||
await db.commit()
|
||||
print(f"价格库: 新增 {lib_stats['created']} / 更新 {lib_stats['updated']}")
|
||||
print(f"系列模板: {series_ids}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
company = 1
|
||||
if "--company" in sys.argv:
|
||||
company = int(sys.argv[sys.argv.index("--company") + 1])
|
||||
asyncio.run(seed(company))
|
||||
Reference in New Issue
Block a user