feat: 两库对等物料管理及产品工号贯通全流程
- 新增 MES 本地物料表及双向同步接口,WMS 物料变更自动同步 - 全流程新增产品工号字段,贯通入库/库存/出库/检验环节 - 工单管理支持多工单混产,移除单工单互斥限制 - 新增批次号/SN 字段支持质量检验联动 WMS 库存处置 - 修复权限规则,仅内置管理员账号不允许修改删除 - 工位终端新增 SN 扫码自动切换所属工单功能
This commit is contained in:
@@ -130,6 +130,7 @@ func deductStockHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
if obType != "refill" {
|
||||
obType = "workorder"
|
||||
}
|
||||
pw := "" // 产品工号:从源库存取,出库单创建后回填(五页带出)
|
||||
ob, err := tx.OutboundOrder.Create().
|
||||
SetOutboundNo(outboundNo).
|
||||
SetOutboundType(obType).
|
||||
@@ -163,6 +164,7 @@ func deductStockHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
fail(w, http.StatusBadRequest, "批次不存在: "+req.BatchNo)
|
||||
return
|
||||
}
|
||||
pw = b.ProductWorkNo // 取源库存产品工号,回填出库单
|
||||
avail := b.Quantity - b.LockedQty
|
||||
if avail < req.Qty {
|
||||
fail(w, http.StatusConflict, "批次库存不足: "+req.BatchNo+" 可用 "+itoa(avail))
|
||||
@@ -199,6 +201,11 @@ func deductStockHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
// 质量门禁(P0-2,客户口径):仅「合格」SN 可出库(未检/不合格/待退 拦截;退货/报废走「通用出库」)
|
||||
if len(req.SnList) > 0 {
|
||||
for _, sn := range req.SnList {
|
||||
if pw == "" {
|
||||
if inv, e := tx.Inventory.Query().Where(inventory.SnCodeEQ(sn)).Only(ctx0()); e == nil {
|
||||
pw = inv.ProductWorkNo
|
||||
}
|
||||
}
|
||||
aff, err := tx.Inventory.Update().
|
||||
Where(inventory.ManageModeEQ(2), inventory.SnCodeEQ(sn), inventory.StatusIn("在库", "锁定"),
|
||||
inventory.QualityStatusEQ(QStatusPass)).
|
||||
@@ -227,6 +234,14 @@ func deductStockHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
actualQty = len(req.SnList)
|
||||
}
|
||||
|
||||
// 4.5 回填产品工号(从源库存取,五页带出展示/筛选)
|
||||
if pw != "" {
|
||||
if _, e := tx.OutboundOrder.UpdateOneID(ob.ID).SetNillableProductWorkNo(strPtr(pw)).Save(ctx0()); e != nil {
|
||||
fail(w, http.StatusInternalServerError, "回填产品工号失败: "+e.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 更新出库单实际数量
|
||||
if _, err = tx.OutboundOrder.UpdateOneID(ob.ID).
|
||||
SetQuantity(actualQty).Save(ctx0()); err != nil {
|
||||
@@ -365,6 +380,9 @@ func queryOutboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
if inspectionNo != "" {
|
||||
q = q.Where(outboundorder.InspectionNoContainsFold(inspectionNo))
|
||||
}
|
||||
if v := r.URL.Query().Get("productWorkNo"); v != "" {
|
||||
q = q.Where(outboundorder.ProductWorkNoContainsFold(v))
|
||||
}
|
||||
if v := r.URL.Query().Get("startDate"); v != "" {
|
||||
if t, err := time.ParseInLocation("2006-01-02", v, time.Local); err == nil {
|
||||
q = q.Where(outboundorder.CreatedAtGTE(t.Unix()))
|
||||
@@ -515,6 +533,7 @@ func generalOutboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}()
|
||||
|
||||
pw := "" // 产品工号:从源库存取,出库单创建后回填(五页带出)
|
||||
ob, err := tx.OutboundOrder.Create().
|
||||
SetOutboundNo(outboundNo).
|
||||
SetOutboundType("general").
|
||||
@@ -553,6 +572,7 @@ func generalOutboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
fail(w, http.StatusBadRequest, "批次不存在: "+req.BatchNo)
|
||||
return
|
||||
}
|
||||
pw = b.ProductWorkNo // 取源库存产品工号,回填出库单
|
||||
// 质量门禁(U5,客户口径):发货/样品/其他类出库仅允许「合格」品流向下游;
|
||||
// 退货/报废/退料类豁免(本身即处置不合格品)。
|
||||
if outboundBlocksUnqualified(req.OutboundCategory) && b.QualityStatus != QStatusPass {
|
||||
@@ -597,6 +617,11 @@ func generalOutboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
for _, sn := range req.SnList {
|
||||
if pw == "" {
|
||||
if inv, e := tx.Inventory.Query().Where(inventory.SnCodeEQ(sn)).Only(ctx0()); e == nil {
|
||||
pw = inv.ProductWorkNo
|
||||
}
|
||||
}
|
||||
aff, err := tx.Inventory.Update().
|
||||
Where(inventory.ManageModeEQ(2), inventory.SnCodeEQ(sn), inventory.StatusIn("在库", "锁定")).
|
||||
SetStatus("出库").
|
||||
@@ -632,6 +657,14 @@ func generalOutboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
// 回填产品工号(从源库存取,五页带出展示/筛选)
|
||||
if pw != "" {
|
||||
if _, e := tx.OutboundOrder.UpdateOneID(ob.ID).SetNillableProductWorkNo(strPtr(pw)).Save(ctx0()); e != nil {
|
||||
fail(w, http.StatusInternalServerError, "回填产品工号失败: "+e.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err = tx.Commit(); err != nil {
|
||||
fail(w, http.StatusInternalServerError, "提交事务失败: "+err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user