2026-08-28 15:06:01 +08:00
|
|
|
|
package schema
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"entgo.io/ent"
|
2026-10-08 13:09:53 +08:00
|
|
|
|
"entgo.io/ent/dialect/entsql"
|
|
|
|
|
|
"entgo.io/ent/schema"
|
2026-08-28 15:06:01 +08:00
|
|
|
|
"entgo.io/ent/schema/field"
|
|
|
|
|
|
"entgo.io/ent/schema/index"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2026-09-03 14:20:37 +08:00
|
|
|
|
// OutboundOrder 出库统一主表
|
2026-09-19 17:04:58 +08:00
|
|
|
|
// 所有出库(备料出库 workorder / 补料出库 refill / 通用出库 general)都落在这一张表,
|
2026-09-03 14:20:37 +08:00
|
|
|
|
// 用 outbound_type 区分;装箱属性(箱号/SN清单/合同号)直接存本表,不再单独建装箱表。
|
2026-10-10 15:58:59 +08:00
|
|
|
|
// 备料出库强约束:净领用(out_qty − returned_qty) ≤ 工单物料清单需求量,由 WMS 侧台账校验。
|
2026-09-19 17:04:58 +08:00
|
|
|
|
//
|
|
|
|
|
|
// 注:报工反冲不再生成出库单(2026-09-19 起反冲只核销台账 consumed_qty,不做物理位移)。
|
2026-08-28 15:06:01 +08:00
|
|
|
|
type OutboundOrder struct {
|
|
|
|
|
|
ent.Schema
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-08 13:09:53 +08:00
|
|
|
|
func (OutboundOrder) Annotations() []schema.Annotation {
|
|
|
|
|
|
return []schema.Annotation{entsql.Table("outbound_orders"), entsql.WithComments(true), schema.Comment("OutboundOrder 出库统一主表")}
|
|
|
|
|
|
}
|
2026-08-28 15:06:01 +08:00
|
|
|
|
func (OutboundOrder) Fields() []ent.Field {
|
|
|
|
|
|
return []ent.Field{
|
|
|
|
|
|
field.String("outbound_no").Unique().Comment("出库单号"),
|
2026-09-19 17:04:58 +08:00
|
|
|
|
// 类型:workorder(备料出库/MES) refill(工位叫料补料) general(通用出库,不依赖工单)
|
2026-08-28 15:06:01 +08:00
|
|
|
|
field.String("outbound_type").Default("workorder").Comment("出库类型"),
|
2026-09-19 17:04:58 +08:00
|
|
|
|
// 出库单状态:出库即扣库存,故创建即为「已出库」;叫 AGV 配送到位后置「已送达」。
|
|
|
|
|
|
// 「已接料」不在本表(归备料单 material_request.received_qty),避免三处状态互斗。
|
|
|
|
|
|
field.String("status").Default("已出库").Comment("出库单状态 已出库/已送达"),
|
|
|
|
|
|
field.Bool("need_agv").Default(false).Comment("是否需要AGV配送到接驳台"),
|
2026-09-17 12:49:07 +08:00
|
|
|
|
// 出库类别(客户诉求 问题记录 L96-108):通用出库先点选类别——
|
|
|
|
|
|
// return(退料)/sample(样品)/scrap(报废)/deliver(发货)/other(其他,手输原因)
|
|
|
|
|
|
field.String("outbound_category").Optional().Comment("出库类别 return/sample/scrap/deliver/other"),
|
|
|
|
|
|
// 归属(客户诉求 L96-108):工单号/科技项目号/其他;与入库 ownership_type 口径一致
|
|
|
|
|
|
field.String("ownership_type").Optional().Comment("归属类型 workorder/project/other"),
|
|
|
|
|
|
field.String("ownership_no").Optional().Comment("归属编号(工单号/科技项目号)"),
|
|
|
|
|
|
// 目标工位(客户诉求 L96-108):出库送到哪个装配工位
|
|
|
|
|
|
field.String("target_station").Optional().Comment("目标工位(装配工位号)"),
|
2026-08-28 15:06:01 +08:00
|
|
|
|
field.String("order_no").Optional().Comment("关联工单号(工单为唯一挂靠载体)"),
|
|
|
|
|
|
field.String("material_code").Comment("物料编码"),
|
|
|
|
|
|
field.String("material_name").Optional().Comment("物料名称(冗余)"),
|
2026-09-30 17:33:11 +08:00
|
|
|
|
// 类型(分类语境):1结构件/2电气件/3其他
|
|
|
|
|
|
field.Int("manage_mode").Default(1).Comment("类型 1结构件/2电气件/3其他"),
|
2026-10-10 15:58:59 +08:00
|
|
|
|
// 序列号(2026-09-30 解耦定稿):1序列号=是(逐件SN)/2序列号=否(数量)
|
2026-10-20 16:36:26 +08:00
|
|
|
|
field.Int("sn_mode").Default(0).Comment("序列号 1=是(逐件SN)/2=否(按数量)/0未选择"),
|
2026-08-28 15:06:01 +08:00
|
|
|
|
field.String("batch_no").Optional().Comment("批次号(结构件)"),
|
2026-09-19 17:04:58 +08:00
|
|
|
|
// 出库库位四级(客户诉求:出库与入库同口径,2026-09-19 补齐)
|
|
|
|
|
|
field.String("zone_code").Optional().Comment("出库区域(大区)"),
|
|
|
|
|
|
field.String("shelf_no").Optional().Comment("货架号(与入库同口径)"),
|
|
|
|
|
|
field.String("layer_no").Optional().Comment("第几层(与入库同口径)"),
|
|
|
|
|
|
field.String("position_no").Optional().Comment("位置号(与入库同口径)"),
|
2026-09-02 08:21:11 +08:00
|
|
|
|
field.Int("quantity").Default(0).Comment("本次出库总数量"),
|
2026-08-28 15:06:01 +08:00
|
|
|
|
field.String("operator").Optional().Comment("操作人"),
|
|
|
|
|
|
field.String("reviewer").Optional().Comment("复核人"),
|
|
|
|
|
|
field.String("target_dock").Optional().Comment("目标接驳台(AGV配送)"),
|
|
|
|
|
|
field.String("remark").Optional().Comment("备注"),
|
2026-09-03 14:20:37 +08:00
|
|
|
|
// 装箱属性:出库时一并记录箱号/SN清单/合同号,统一落在出库主表,不再单独建装箱表
|
|
|
|
|
|
field.String("box_no").Optional().Comment("箱号(装箱出库时填写,用于整箱发货追溯)"),
|
|
|
|
|
|
field.String("box_sn_list").Optional().Comment("装箱 SN 清单(JSON 数组字符串)"),
|
|
|
|
|
|
field.String("contract_no").Optional().Comment("合同号(装箱选填)"),
|
2026-11-02 19:17:05 +08:00
|
|
|
|
// 跨工位借料来源(call 备料出库专用):stationNo→借用量;空=本工位自取(不借)。
|
|
|
|
|
|
// 库房备料发货时据此知悉"此单混用了借工位额度",避免糊涂账(2026-11-02 借料知情权)。
|
|
|
|
|
|
field.JSON("borrowFrom", map[string]int{}).Optional().Comment("跨工位借料来源 stationNo→借用量(call 备料出库专用);空=本工位自取"),
|
2026-09-21 15:28:14 +08:00
|
|
|
|
// 检测单号(2026-09-21 对齐入库单字段):退货/报废等需要溯源检验单据的出库场景可选填写
|
|
|
|
|
|
field.String("inspection_no").Optional().Comment("检测单号(溯源关联检验单据)"),
|
2026-09-29 14:55:03 +08:00
|
|
|
|
// 产品工号(随库存带入,出库记录展示/筛选,2026-09-29 五页带出)
|
|
|
|
|
|
field.String("product_work_no").Optional().Comment("产品工号(随库存带入,出库记录展示/筛选)"),
|
2026-11-03 10:17:49 +08:00
|
|
|
|
// 作废(2026-11-03 断头路补全):仅通用出库(general)/科技项目出库(project)可作废——
|
|
|
|
|
|
// 人工手工出库填错时的纠错闭环(对齐入库作废 inbound_void);备料/补料/叫料出库(workorder/refill/call)
|
|
|
|
|
|
// 与 MES 台账联动,不提供作废,走退库逆向闭环。作废=回滚库存+标记保留记录。
|
|
|
|
|
|
field.Bool("voided").Default(false).Comment("是否已作废"),
|
|
|
|
|
|
field.String("void_reason").Default("").Comment("作废原因(必填留痕)"),
|
|
|
|
|
|
field.String("voided_by").Default("").Comment("作废操作人"),
|
|
|
|
|
|
field.Int64("voided_at").Optional().Nillable().Comment("作废时间戳"),
|
2026-09-02 08:21:11 +08:00
|
|
|
|
field.Int64("created_at").DefaultFunc(nowUnix).Comment("创建时间"),
|
2026-08-28 15:06:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (OutboundOrder) Indexes() []ent.Index {
|
|
|
|
|
|
return []ent.Index{
|
|
|
|
|
|
index.Fields("order_no"),
|
|
|
|
|
|
index.Fields("material_code"),
|
|
|
|
|
|
index.Fields("outbound_type"),
|
2026-09-03 14:20:37 +08:00
|
|
|
|
index.Fields("box_no"),
|
2026-09-21 15:28:14 +08:00
|
|
|
|
index.Fields("inspection_no"),
|
2026-08-28 15:06:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|