feat: 新增备料(采购下单)功能模块,含清空清单
- 独立采购备料清单:选 BOM + 输入套数一键生成计划(计划数量 = 单套用量 × 套数),可手工增删改、导出 Excel - 备料与生产订单完全解耦,仅记录计划数量、不记账(不产生任何出入库流水) - 新增「清空清单」功能(/prepare/clear,JS 二次确认 + 操作日志),按当前工厂范围清空 - 配套:PrepPlan 模型、缺口(计划-库存)实时计算、库存随工厂切换过滤
This commit is contained in:
+29
@@ -245,6 +245,35 @@ def export_inventory(path, rows):
|
||||
wb.save(path)
|
||||
|
||||
|
||||
def export_prep(path, rows, scope=""):
|
||||
"""导出备料清单(采购下单用, 不记账; 手工维护, 与生产订单无关)。
|
||||
|
||||
rows: [{id, m, plan(计划数量), stock(实际库存), diff(缺口=计划-库存), short}]
|
||||
scope: 范围说明(工厂/全部)。
|
||||
"""
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "备料清单"
|
||||
head = ["物料编号", "型号/规格", "单位", "计划数量", "实际库存",
|
||||
"缺口(计划-库存)", "状态", "范围"]
|
||||
ws.append(head)
|
||||
for c in ws[1]:
|
||||
c.font = Font(bold=True)
|
||||
c.fill = PatternFill("solid", fgColor="DDEBF7")
|
||||
for r in rows:
|
||||
m = r["m"]
|
||||
status = "需采购" if r["diff"] > 0 else ("刚好够" if r["diff"] == 0 else "已有盈余")
|
||||
ws.append([m.part_number, m.manufacturer or "", m.unit or "个",
|
||||
r["plan"], r["stock"], r["diff"], status, scope])
|
||||
# 缺口着色: >0 需采购标红; <0 盈余标绿
|
||||
if r["diff"] > 0:
|
||||
ws.cell(row=ws.max_row, column=6).fill = PatternFill("solid", fgColor="FFC7CE")
|
||||
elif r["diff"] < 0:
|
||||
ws.cell(row=ws.max_row, column=6).fill = PatternFill("solid", fgColor="C6EFCE")
|
||||
ws.freeze_panes = "A2"
|
||||
wb.save(path)
|
||||
|
||||
|
||||
def build_material_template(path):
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
|
||||
Reference in New Issue
Block a user