feat(in-transit-transfer): inbound/outbound 幂等重命名与解析用途分层

- receipt→inbound 三件套改名(回调桥/文件门禁/触发服务),回调链幂等去重,迁移 tt14 同步台账键与测试基建
- 库存解析用途分层 onhand/inbound/outbound(迁移 tt15):解析档案、文件存储与下载名按用途隔离,管理端表单同步
- 「成熟」概念退役(迁移 tt16):数据无成熟属性,日期边界由调用方入参严格判定
- backlog 新增重解析服务,在途重识别投影 processing,EML 父项不再停留处理中
- 收料 RPA 回调/归档/排程链路同步改名挂点,运维脚本复位假完成状态
- 文档随批:ADR 0003 模块边界决策、10-15/10-16 计划与设计、调拨文档族与 demand/tec/funclist
- 同步 chat/errors 文案四语言、调拨前端卡片与 e2e、测试全家
This commit is contained in:
hugo committed 2026-10-16 19:43:49 +08:00
1 parent 43dceaf027
commit 8102a1fe44
151 files changed
+8057 -2382

No files matched your search

@@ -0,0 +1,89 @@
"""tt14 入站化:receipt_* 列更名 movement_*、record_kind 值迁移、自然键扩 8 成分
Revision ID: tt14a5f6a7b8c9
Revises: mh15f6a7b8c9
Create Date: 2026-10-15 10:00:00.000000
用途:落实 spec D1/D6——真实 WMS 文件行身份是「单据+行+箱/批」,自然键扩
carton_id+lot_no;receipt 说辞一次性更名(无兼容层)。明细/单据列是方向
中立(出站调拨同样产生明细),按控制器裁决用 movement_*(与异动档
transfer_movement_ledger.movement_date 命名对齐),不用 inbound_*。
依赖:mh15f6a7b8c9 为实施时 flask db heads 显示的实际单 head(并行会话已把
eah8c9d0e1f2 与 tt13d4e5f6a7b8 合并,本迁移链接其后避免双头)。
逻辑:batch_alter_table 完成 RENAME(PG/SQLite 双兼容);record_kind 值迁移为
数据 UPDATE(未上线为空操作,test 环境兜底);唯一约束按 8 成分重建,
进键维度列 carton_id/lot_no 同步 NOT NULL + default ''(R7 终审:nullable
成分的 NULL 不参与唯一比对会逃逸约束;落档链路恒写 '',无存量 NULL)。
列类型取自建表迁移(it1a2b3c4d5e/it2c3d4e5f6a7/tt0d1e2f3a4b)逐一核对。
"""
from alembic import op
import sqlalchemy as sa
revision = "tt14a5f6a7b8c9"
down_revision = "mh15f6a7b8c9"
branch_labels = None
depends_on = None
def upgrade() -> None:
"""receipt_* 列更名 movement_*、record_kind 值迁移 receipt→inbound、自然键扩 8 成分。"""
with op.batch_alter_table("transfer_invoice_items") as batch:
batch.alter_column("receipt_date", new_column_name="movement_date",
existing_type=sa.String(length=16), existing_nullable=True)
batch.alter_column("receipt_quantity", new_column_name="movement_quantity",
existing_type=sa.String(length=40), existing_nullable=False)
batch.alter_column("receipt_warehouse_code", new_column_name="movement_warehouse_code",
existing_type=sa.String(length=64), existing_nullable=False)
with op.batch_alter_table("transfer_documents") as batch:
batch.alter_column("receipt_date", new_column_name="movement_date",
existing_type=sa.String(length=16), existing_nullable=False)
op.execute("UPDATE transfer_movement_ledger SET record_kind='inbound' WHERE record_kind='receipt'")
op.execute("UPDATE transfer_movement_ledger SET record_kind='outbound' WHERE record_kind='shipment'")
with op.batch_alter_table("transfer_movement_ledger") as batch:
# R7(终审修复):carton_id/lot_no 进键即 NOT NULL + default ''——nullable
# 成分在 PG/SQLite 唯一比对中 NULL≠NULL,会逃逸唯一约束(同箱同批塌缩)。
# 落档链路恒写 '',无存量 NULL(未上线),SET NOT NULL 安全。
batch.alter_column("carton_id", existing_type=sa.String(length=64),
nullable=False, server_default='', existing_server_default=None)
batch.alter_column("lot_no", existing_type=sa.String(length=64),
nullable=False, server_default='', existing_server_default=None)
batch.drop_constraint("uq_transfer_movement_ledger_natural_key", type_="unique")
batch.create_unique_constraint(
"uq_transfer_movement_ledger_natural_key",
["source_code", "record_kind", "doc_no", "line_no", "line_seq",
"in_out_flag", "carton_id", "lot_no"],
)
def downgrade() -> None:
"""回滚:自然键收回 6 成分、维度列还原可空无默认、record_kind 值还原、列名还原。
注意:收窄为 6 成分唯一约束时,要求不存在同 6 元组异 carton/lot 并存数据,
否则约束重建 IntegrityError(固有语义,非缺陷——6 成分键本就无法区分同键多箱/批)。
"""
with op.batch_alter_table("transfer_movement_ledger") as batch:
# 对称还原 tt14 upgrade:server_default=None 渲染 DROP DEFAULT(PG),SQLite
# batch 重建表时不携带默认值(alembic 1.19 语义,False=不动、None=移除)。
batch.alter_column("carton_id", existing_type=sa.String(length=64),
nullable=True, server_default=None, existing_server_default='')
batch.alter_column("lot_no", existing_type=sa.String(length=64),
nullable=True, server_default=None, existing_server_default='')
batch.drop_constraint("uq_transfer_movement_ledger_natural_key", type_="unique")
batch.create_unique_constraint(
"uq_transfer_movement_ledger_natural_key",
["source_code", "record_kind", "doc_no", "line_no", "line_seq", "in_out_flag"],
)
op.execute("UPDATE transfer_movement_ledger SET record_kind='receipt' WHERE record_kind='inbound'")
op.execute("UPDATE transfer_movement_ledger SET record_kind='shipment' WHERE record_kind='outbound'")
with op.batch_alter_table("transfer_documents") as batch:
batch.alter_column("movement_date", new_column_name="receipt_date",
existing_type=sa.String(length=16), existing_nullable=False)
with op.batch_alter_table("transfer_invoice_items") as batch:
batch.alter_column("movement_date", new_column_name="receipt_date",
existing_type=sa.String(length=16), existing_nullable=True)
batch.alter_column("movement_quantity", new_column_name="receipt_quantity",
existing_type=sa.String(length=40), existing_nullable=False)
batch.alter_column("movement_warehouse_code", new_column_name="receipt_warehouse_code",
existing_type=sa.String(length=64), existing_nullable=False)
@@ -0,0 +1,66 @@
"""tt15 purpose 枚举改版:inventory/movement → onhand/inbound/outbound
Revision ID: tt15b6a7b8c9d0
Revises: tt14a5f6a7b8c9
Create Date: 2026-10-15 12:00:00.000000
用途:通用文件解析规则表 shipping_inventory_parsing_profiles.purpose 由二值
(inventory / movement)扩为方向化三元枚举(onhand / inbound / outbound):
onhand=在手库存文件(原 inventory),inbound=入站收料文件(原 movement),
outbound=出站文件(结构就位,暂无运行时消费方)。
依赖:tt14a5f6a7b8c9 为实施时 flask db heads 显示的实际单 head;purpose 列与旧
CHECK 由 b17e3d4c5a60 / if1b2c3d4e5g 建立。
逻辑:四个操作按序执行——DROP 旧 CHECK → 数据 UPDATE(inventory→onhand、
movement→inbound)→ ADD 新 CHECK → SET DEFAULT 'onhand'。SQLite 不支持裸
ALTER TABLE DROP CONSTRAINT / ALTER COLUMN SET DEFAULT,故 DDL 全部走
batch_alter_table(batch 重建表,SQLite 往返可执行),PG 端渲染等价于裸
ALTER 语句;数据 UPDATE 用 op.execute 独立执行(不进 batch)。
downgrade 对称:outbound 行无 1:1 旧值,迁移到 'movement'(结构就位语义最接近)。
"""
from alembic import op
import sqlalchemy as sa
revision = "tt15b6a7b8c9d0"
down_revision = "tt14a5f6a7b8c9"
branch_labels = None
depends_on = None
def upgrade() -> None:
"""purpose 枚举改版:换 CHECK、迁移存量值、default 置 'onhand'。"""
with op.batch_alter_table("shipping_inventory_parsing_profiles") as batch:
batch.drop_constraint(
"ck_shipping_inventory_parsing_profiles_purpose", type_="check",
)
op.execute("UPDATE shipping_inventory_parsing_profiles SET purpose='onhand' WHERE purpose='inventory'")
op.execute("UPDATE shipping_inventory_parsing_profiles SET purpose='inbound' WHERE purpose='movement'")
with op.batch_alter_table("shipping_inventory_parsing_profiles") as batch:
batch.create_check_constraint(
"ck_shipping_inventory_parsing_profiles_purpose",
"purpose IN ('onhand', 'inbound', 'outbound')",
)
batch.alter_column(
"purpose", existing_type=sa.String(length=16), existing_nullable=False,
server_default="onhand", existing_server_default="inventory",
)
def downgrade() -> None:
"""回滚:default 还原 'inventory'、换回旧 CHECK,存量值对称还原(outbound→movement)。"""
with op.batch_alter_table("shipping_inventory_parsing_profiles") as batch:
batch.drop_constraint(
"ck_shipping_inventory_parsing_profiles_purpose", type_="check",
)
batch.alter_column(
"purpose", existing_type=sa.String(length=16), existing_nullable=False,
server_default="inventory", existing_server_default="onhand",
)
op.execute("UPDATE shipping_inventory_parsing_profiles SET purpose='inventory' WHERE purpose='onhand'")
op.execute("UPDATE shipping_inventory_parsing_profiles SET purpose='movement' WHERE purpose IN ('inbound', 'outbound')")
with op.batch_alter_table("shipping_inventory_parsing_profiles") as batch:
batch.create_check_constraint(
"ck_shipping_inventory_parsing_profiles_purpose",
"purpose IN ('inventory', 'movement')",
)
@@ -0,0 +1,62 @@
"""retire not_matured item status (maturity concept removal 2026-10-16)
Revision ID: tt16a7b8c9d0e1f2
Revises: tt15b6a7b8c9d0
Create Date: 2026-10-16
用途:「成熟」概念退役(用户裁定:数据无成熟属性,日期边界由调用方入参严格
给定)——transfer_invoice_items.status 冻结枚举删去 'not_matured'
(13 态 → 12 态),CHECK 约束 ck_transfer_invoice_items_status 同步重建。
数据迁移:存量 not_matured 行重映射为 'cancelled'(语义最近=未进入执行且不再
可执行;D17 占用过滤本就排除 cancelled,占用随之自然释放)。result_code
保留历史值 'not_matured' 不改写(无约束的自由文本,留审计溯源)。
降级:仅重建旧 CHECK(含 not_matured);已重映射的行无法还原原状态(dev 数据,
有损降级,docstring 如实声明)。
依赖:无数据依赖;与 tt14/tt15 并行域迁移同链(单 head 顺序 tt14→tt15→tt16)。
"""
from alembic import op
revision = 'tt16a7b8c9d0e1f2'
down_revision = 'tt15b6a7b8c9d0'
branch_labels = None
depends_on = None
# 12 态枚举(与 app.models.in_transit_transfer.TRANSFER_ITEM_STATUSES 同步;
# 迁移文件不 import 应用模型,避免迁移期模型漂移牵连)。
_ITEM_STATUSES_V12 = (
'file_pending', 'file_ready', 'matching', 'ready_to_execute', 'executing',
'success', 'duplicate_success', 'blocked_recoverable',
'result_unknown', 'manually_closed', 'cancelled', 'notification_failed',
)
_ITEM_STATUSES_V13 = ('not_matured',) + _ITEM_STATUSES_V12[:8] + _ITEM_STATUSES_V12[8:]
def _statuses_sql(statuses: tuple[str, ...]) -> str:
return ', '.join(repr(s) for s in statuses)
def upgrade() -> None:
# [STEP 1] 存量 not_matured 行重映射 cancelled(必须先于 CHECK 重建,否则
# 旧值撞新约束);占用释放由 D17 占用过滤排除 cancelled 自然达成。
op.execute(
"UPDATE transfer_invoice_items SET status = 'cancelled' "
"WHERE status = 'not_matured'"
)
# [STEP 2] CHECK 重建:旧约束 → 12 态新约束。
op.drop_constraint('ck_transfer_invoice_items_status', 'transfer_invoice_items', type_='check')
op.create_check_constraint(
'ck_transfer_invoice_items_status',
'transfer_invoice_items',
f"status IN ({_statuses_sql(_ITEM_STATUSES_V12)})",
)
def downgrade() -> None:
# [STEP 1] CHECK 回退到 13 态(已重映射的 cancelled 行无法识别还原,有损降级)。
op.drop_constraint('ck_transfer_invoice_items_status', 'transfer_invoice_items', type_='check')
op.create_check_constraint(
'ck_transfer_invoice_items_status',
'transfer_invoice_items',
f"status IN ({_statuses_sql(_ITEM_STATUSES_V13)})",
)