Merge branch 'dev' into picture-feedback
This commit is contained in:
commit
34ad40778b
180 files changed
+13262
-5333
No files matched your search
@@ -46,26 +46,56 @@ from app.path_utils import resolve_backend_relative_path
|
||||
from app.services.file_assets.storage import file_asset_storage
|
||||
|
||||
|
||||
def _released_line_indexes_for_task(order_task_id: int) -> set[int]:
|
||||
"""按正式 OT 身份读取已审计短缺放行的行号集合(复核 Case 的 confirmed_task_id 恒为 OT id)。"""
|
||||
from app.models import ShippingOrderReviewCase, ShippingOrderReviewLineDecision
|
||||
|
||||
rows = (
|
||||
ShippingOrderReviewLineDecision.query
|
||||
.join(
|
||||
ShippingOrderReviewCase,
|
||||
ShippingOrderReviewLineDecision.review_case_id == ShippingOrderReviewCase.id,
|
||||
)
|
||||
.filter(
|
||||
ShippingOrderReviewCase.confirmed_task_id == int(order_task_id),
|
||||
ShippingOrderReviewLineDecision.is_active.is_(True),
|
||||
ShippingOrderReviewLineDecision.decision_code == 'release_onhand_shortage',
|
||||
ShippingOrderReviewLineDecision.line_index.isnot(None),
|
||||
)
|
||||
.all()
|
||||
)
|
||||
return {int(row.line_index) for row in rows}
|
||||
|
||||
|
||||
def _notice_source_code(task: ShippingNotice) -> str | None:
|
||||
"""返回正式 Notice 行级匹配中唯一使用的库存源;多源导出必须显式拒绝。
|
||||
|
||||
匹配事实的 task_id 挂在正式 OT 上:传 Notice 时取 order_task_id,
|
||||
传 OT 本身时取 id(整单 ODM 候选投影会在物化前以 OT 调用)。
|
||||
已审计短缺放行行(release_onhand_shortage)的 match_result 恒为 not_found
|
||||
(如预约键 0 命中的料号兜底行),其事实源码与 matched 行同票参与唯一性
|
||||
裁决;只按 matched 过滤会让「整单放行」的单永远解析不到库存源
|
||||
(回归 OT-20261027-4BD4CEFF)。
|
||||
"""
|
||||
task_id = getattr(task, 'order_task_id', None) or getattr(task, 'id', None)
|
||||
if task_id is None:
|
||||
return None
|
||||
task_id = int(task_id)
|
||||
released_line_indexes = _released_line_indexes_for_task(task_id)
|
||||
codes = [
|
||||
str(row[0]).strip().upper()
|
||||
for row in db.session.query(ShippingNoticeLineOnhandMatch.source_code).filter(
|
||||
for row in db.session.query(
|
||||
ShippingNoticeLineOnhandMatch.source_code,
|
||||
ShippingNoticeLineOnhandMatch.match_result,
|
||||
ShippingNoticeLineOnhandMatch.line_index,
|
||||
).filter(
|
||||
ShippingNoticeLineOnhandMatch.task_id == task_id,
|
||||
ShippingNoticeLineOnhandMatch.is_current.is_(True),
|
||||
ShippingNoticeLineOnhandMatch.match_result == 'matched',
|
||||
ShippingNoticeLineOnhandMatch.source_code.isnot(None),
|
||||
).distinct().all()
|
||||
if row[0]
|
||||
).all()
|
||||
if row[0] and (row[1] == 'matched' or (row[2] is not None and int(row[2]) in released_line_indexes))
|
||||
]
|
||||
codes = list(dict.fromkeys(codes))
|
||||
return codes[0] if len(codes) == 1 else None
|
||||
|
||||
|
||||
@@ -87,19 +117,31 @@ def _notice_chosen_odm(task: ShippingNotice) -> str | None:
|
||||
|
||||
|
||||
def _notice_inventory_file_id(task: ShippingNotice) -> int | None:
|
||||
"""从 Notice 行级匹配读取本次导出的唯一库存文件。"""
|
||||
"""从 Notice 行级匹配读取本次导出的唯一库存文件。
|
||||
|
||||
已审计短缺放行行(not_found 事实)的证据快照与 matched 行同票:整单放行时
|
||||
库存证据文件仍必须落 Artifact 审计,否则证据流断链(回归 OT-20261027-4BD4CEFF)。
|
||||
"""
|
||||
task_id = getattr(task, 'order_task_id', None)
|
||||
if task_id is None:
|
||||
return None
|
||||
task_id = int(task_id)
|
||||
released_line_indexes = _released_line_indexes_for_task(task_id)
|
||||
ids = [
|
||||
int(row[0]) for row in db.session.query(ShippingNoticeLineOnhandMatch.onhand_snapshot_id).filter(
|
||||
int(row[0]) for row in db.session.query(
|
||||
ShippingNoticeLineOnhandMatch.onhand_snapshot_id,
|
||||
ShippingNoticeLineOnhandMatch.match_result,
|
||||
ShippingNoticeLineOnhandMatch.line_index,
|
||||
).filter(
|
||||
ShippingNoticeLineOnhandMatch.task_id == task_id,
|
||||
ShippingNoticeLineOnhandMatch.is_current.is_(True),
|
||||
ShippingNoticeLineOnhandMatch.match_result == 'matched',
|
||||
ShippingNoticeLineOnhandMatch.onhand_snapshot_id.isnot(None),
|
||||
).distinct().all()
|
||||
).all()
|
||||
if row[0] is not None and (
|
||||
row[1] == 'matched' or (row[2] is not None and int(row[2]) in released_line_indexes)
|
||||
)
|
||||
]
|
||||
ids = list(dict.fromkeys(ids))
|
||||
return ids[0] if len(ids) == 1 else None
|
||||
|
||||
|
||||
@@ -799,8 +841,14 @@ def prepare_export_match_inputs(task: ShippingNotice) -> dict[str, Any]:
|
||||
header_inventory_fields = _inventory_fields_by_mode(mappings, 'header')
|
||||
# [STEP 1] 短缺放行的人工字段仅从该行的活动决定审计快照读取,
|
||||
# 只能补模板行级库存字段,不能污染快照或任务级库存输入。
|
||||
# [身份口径] 复核 Case.confirmed_task_id 恒为正式 OT id;本函数入参可能是
|
||||
# 换绑后的 Notice,必须经 order_task_id 回链 OT,否则放行/结案决定恒查空,
|
||||
# 放行行进不了导出资格、结案行漏剔除(与 _facts_order_task 同款键位纪律)。
|
||||
from app.models import ShippingOrderReviewCase, ShippingOrderReviewLineDecision
|
||||
|
||||
order_task_id_for_decisions = int(
|
||||
getattr(source_notice, 'order_task_id', None) or source_notice.id
|
||||
)
|
||||
release_overrides_by_source_line: dict[int, dict[str, Any]] = {}
|
||||
released_source_line_indexes: set[int] = set()
|
||||
if source_notice.id is not None:
|
||||
@@ -808,7 +856,7 @@ def prepare_export_match_inputs(task: ShippingNotice) -> dict[str, Any]:
|
||||
ShippingOrderReviewLineDecision.query
|
||||
.join(ShippingOrderReviewCase, ShippingOrderReviewLineDecision.review_case_id == ShippingOrderReviewCase.id)
|
||||
.filter(
|
||||
ShippingOrderReviewCase.confirmed_task_id == int(source_notice.id),
|
||||
ShippingOrderReviewCase.confirmed_task_id == order_task_id_for_decisions,
|
||||
ShippingOrderReviewLineDecision.is_active.is_(True),
|
||||
ShippingOrderReviewLineDecision.decision_code == 'release_onhand_shortage',
|
||||
)
|
||||
@@ -835,7 +883,7 @@ def prepare_export_match_inputs(task: ShippingNotice) -> dict[str, Any]:
|
||||
ShippingOrderReviewLineDecision.query
|
||||
.join(ShippingOrderReviewCase, ShippingOrderReviewLineDecision.review_case_id == ShippingOrderReviewCase.id)
|
||||
.filter(
|
||||
ShippingOrderReviewCase.confirmed_task_id == int(source_notice.id),
|
||||
ShippingOrderReviewCase.confirmed_task_id == order_task_id_for_decisions,
|
||||
ShippingOrderReviewLineDecision.is_active.is_(True),
|
||||
ShippingOrderReviewLineDecision.decision_code == 'close_unfulfillable',
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user