fix(shipping-notice): 打通短缺放行链路的证据读点、决策码迁移与整单放行导出
生产实证(OT-20261027-4BD4CEFF):料号兜底自动放行不触发的根因是 s18 改名 漏迁移放行证据读点,getattr(source,'parsing_profile') 恒 None,致自动/人工 放行全部静默失败。三段修复: 1. 放行证据解析改读 source.onhand_report_config.parsing_profile (与 require_source_profile 同口径)。 2. 补批次 S 漏网迁移 s20a1b2c3d4e:复核行决策码 inventory→onhand 值替换, 重建 ck_shipping_review_line_decisions_code(dev 往返验证后已应用 prod)。 3. 导出链回链 OT:_notice_source_code/_notice_inventory_file_id 纳入已审计 放行行事实(整单放行不再报「库存源不存在」/丢证据快照); prepare_export_match_inputs 放行/结案决定 join 按 confirmed_task_id(OT) 回链。 回归:test_export_released_shortage_only_notice_resolves_source_and_rows (先红后绿)等 117 项全绿。
This commit is contained in:
1 parent
440afe097f
commit
f5611d6783
4 files changed
+222
-15
No files matched your search
@@ -0,0 +1,75 @@
|
||||
"""
|
||||
migrations/versions/s20a1b2c3d4e_review_line_decision_code_rename.py
|
||||
|
||||
用途:批次 S 漏网补丁——复核行决定表的决策码迁移。
|
||||
s17b(表改名)/s17c(枚举数据替换)/s18 均未覆盖
|
||||
shipping_order_review_line_decisions.decision_code:旧码数据不搬、
|
||||
ck_shipping_review_line_decisions_code 不重建,导致新代码写入
|
||||
release_onhand_shortage / wait_onhand 时撞 prod 旧 CHECK
|
||||
(IntegrityError,自动放行被吞、人工放行报错)。
|
||||
依赖:alembic.op、SQLAlchemy;down_revision 为 mh23e4f5a6b7(现仓库唯一 head)。
|
||||
逻辑:先 drop 旧 CHECK(否则新码 UPDATE 直接违约),再做两次精确值替换
|
||||
(release_inventory_shortage→release_onhand_shortage、
|
||||
wait_inventory→wait_onhand,其余码不变),最后按
|
||||
models/shipping_order_review_line_decision.py 的现行码集重建同名 CHECK。
|
||||
line_status 的 CHECK 已是新集(released_shortage 早已在列),本迁移不动。
|
||||
snapshot_json 内的历史码是审计快照,按不可变原则不改写。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = "s20a1b2c3d4e"
|
||||
down_revision = "mh23e4f5a6b7"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLE = "shipping_order_review_line_decisions"
|
||||
_CHECK = "ck_shipping_review_line_decisions_code"
|
||||
|
||||
# 与模型 CheckConstraint 逐字一致的新码集(升级方向)
|
||||
_NEW_CODES = (
|
||||
"'wait_onhand', 'use_new_inventory_file', 'change_inventory_source', "
|
||||
"'fulfill_complete_line_now', 'close_unfulfillable', 'reopen', 'release_onhand_shortage'"
|
||||
)
|
||||
# hg1i2j3k4l5m 时的旧码集(降级方向)
|
||||
_OLD_CODES = (
|
||||
"'wait_inventory', 'use_new_inventory_file', 'change_inventory_source', "
|
||||
"'fulfill_complete_line_now', 'close_unfulfillable', 'reopen', 'release_inventory_shortage'"
|
||||
)
|
||||
|
||||
# 旧码 → 新码(词根 inventory→onhand 的两个改名对;升级方向)
|
||||
_UPDATES_UP: tuple[tuple[str, str], ...] = (
|
||||
("release_inventory_shortage", "release_onhand_shortage"),
|
||||
("wait_inventory", "wait_onhand"),
|
||||
)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# [STEP 1] 先摘旧 CHECK:旧码集不含新码,先改值必违约。
|
||||
op.drop_constraint(_CHECK, _TABLE, type_="check")
|
||||
# [STEP 2] 精确值替换(只碰两个改名对,其余决策码保持原值)。
|
||||
for old, new in _UPDATES_UP:
|
||||
op.execute(
|
||||
sa.text(
|
||||
f"UPDATE {_TABLE} SET decision_code = :new WHERE decision_code = :old"
|
||||
).bindparams(old=old, new=new)
|
||||
)
|
||||
# [STEP 3] 按模型现行码集重建同名 CHECK。
|
||||
op.create_check_constraint(_CHECK, _TABLE, f"decision_code IN ({_NEW_CODES})")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# [STEP 1] 先摘新 CHECK,再把新码精确换回旧码。
|
||||
op.drop_constraint(_CHECK, _TABLE, type_="check")
|
||||
for old, new in _UPDATES_UP:
|
||||
op.execute(
|
||||
sa.text(
|
||||
f"UPDATE {_TABLE} SET decision_code = :old WHERE decision_code = :new"
|
||||
).bindparams(old=old, new=new)
|
||||
)
|
||||
# [STEP 2] 恢复旧码集 CHECK。
|
||||
op.create_check_constraint(_CHECK, _TABLE, f"decision_code IN ({_OLD_CODES})")
|
||||
Reference in new issue
Block a user