Merge branch 'dev' into picture-feedback
This commit is contained in:
commit
34ad40778b
180 files changed
+13262
-5333
No files matched your search
@@ -142,7 +142,7 @@ def _freeze_export_snapshot(
|
||||
|
||||
def _materialize_export_notice(
|
||||
*, ot: ShippingOrderTask, snapshot: ShippingOrderSnapshot, inventory_file: FreightRpaOnhandReportFile,
|
||||
source_code: str, notice_no: str,
|
||||
source_code: str, notice_no: str, match_result: str = 'matched',
|
||||
) -> ShippingNotice:
|
||||
"""从 OT 的冻结快照构造正式 Notice、NoticeLine、匹配事实与活动库存链接。
|
||||
|
||||
@@ -168,7 +168,8 @@ def _materialize_export_notice(
|
||||
for line in snapshot.lines:
|
||||
db.session.add(ShippingNoticeLineOnhandMatch(
|
||||
task_id=ot.id, snapshot_line_id=line.id, line_no=line.line_no,
|
||||
match_result='matched', onhand_status='ready',
|
||||
line_index=int(line.line_no) - 1,
|
||||
match_result=match_result, onhand_status='ready',
|
||||
onhand_snapshot_id=inventory_file.id, source_code=source_code,
|
||||
is_current=True, detail_json={},
|
||||
))
|
||||
@@ -922,6 +923,8 @@ def test_export_commit_failure_removes_generated_file(app, tmp_path, monkeypatch
|
||||
|
||||
def _build_multi_odm_notice(
|
||||
*, tmp_path, odm_values=None, customer_odm_ids=None, choice_odm=None, line_specs=None,
|
||||
released_shortage: bool = False, unreleased_shortage: bool = False,
|
||||
order_part: str = 'PN-A', inventory_part: str | None = None,
|
||||
):
|
||||
"""
|
||||
构造「订单行命中多个 ODM ID」的整单导出场景;须在 app_context 内调用。
|
||||
@@ -931,6 +934,11 @@ def _build_multi_odm_notice(
|
||||
line_specs: 多订单行场景 [{'part': 料号, 'odm_values': [...]}];提供时忽略 odm_values。
|
||||
customer_odm_ids: 客户数据的 ODM ID 范围(None = 不限定)。
|
||||
choice_odm: 整单用户选择(写入 OT.chosen_odm_id)
|
||||
released_shortage: True 时唯一行构造为短缺放行场景——订单料号不在库存行
|
||||
(匹配键 0 命中)、事实落 not_found、并落已确认复核 Case 的系统放行决定
|
||||
(release_field_values 携带 ODM 证据值),整单无任何 matched 事实。
|
||||
unreleased_shortage: True 时事实落 not_found 但不落放行决定(未放行短缺)。
|
||||
order_part / inventory_part: 订单行与库存行的料号(放行场景两者必须不同)。
|
||||
Returns:
|
||||
(notice, customer)。
|
||||
"""
|
||||
@@ -979,7 +987,7 @@ def _build_multi_odm_notice(
|
||||
task_id=ot.id, schema_version_id=version.id, input_snapshot_hash='i' * 64, status='accepted',
|
||||
)
|
||||
db.session.add(extraction); db.session.flush()
|
||||
specs = line_specs or [{'part': 'PN-A', 'odm_values': odm_values}]
|
||||
specs = line_specs or [{'part': order_part, 'odm_values': odm_values}]
|
||||
snapshot_lines = []
|
||||
for index, spec in enumerate(specs, start=1):
|
||||
order_line = ShippingOrderLine(extraction_id=extraction.id, position=index, line_no=index)
|
||||
@@ -998,7 +1006,7 @@ def _build_multi_odm_notice(
|
||||
inventory_rows = []
|
||||
for spec in specs:
|
||||
for odm in spec['odm_values']:
|
||||
inventory_rows.append({_inventory_field_id('part_number'): spec['part'], _inventory_field_id('odm_id'): odm})
|
||||
inventory_rows.append({_inventory_field_id('part_number'): inventory_part or spec['part'], _inventory_field_id('odm_id'): odm})
|
||||
inventory_file = FreightRpaOnhandReportFile(
|
||||
onhand_file_no='SIF-ODMSCOPE', user_id=None, source_file_name='odm-scope.xlsx',
|
||||
storage_path=str(tmp_path / 'odm-scope.xlsx'),
|
||||
@@ -1014,7 +1022,25 @@ def _build_multi_odm_notice(
|
||||
)
|
||||
notice = _materialize_export_notice(
|
||||
ot=ot, snapshot=snapshot, inventory_file=inventory_file, source_code='ODMSCOPE', notice_no='TASK-ODMSCOPE',
|
||||
match_result='not_found' if (released_shortage or unreleased_shortage) else 'matched',
|
||||
)
|
||||
if released_shortage:
|
||||
from app.models import ShippingOrderReviewCase, ShippingOrderReviewLineDecision
|
||||
case = ShippingOrderReviewCase(
|
||||
case_no='CASE-ODMSCOPE-RELEASE', run_id=931, unit_id=932, document_id=933,
|
||||
owner_user_id=1, status='confirmed', confirmed_task_id=int(ot.id),
|
||||
)
|
||||
db.session.add(case); db.session.flush()
|
||||
db.session.add(ShippingOrderReviewLineDecision(
|
||||
review_case_id=case.id, draft_line_id='line-1', line_index=0,
|
||||
decision_code='release_onhand_shortage', decision_source='system',
|
||||
line_status='released_shortage', is_active=True,
|
||||
snapshot_json={
|
||||
'release_field_values': {str(_inventory_field_id('odm_id')): 'ODM-1'},
|
||||
'release_evidence_scope': 'part_fallback',
|
||||
},
|
||||
))
|
||||
db.session.flush()
|
||||
if choice_odm is not None:
|
||||
for match in ShippingNoticeLineOnhandMatch.query.filter_by(task_id=int(ot.id), is_current=True).all():
|
||||
match.chosen_odm_id = choice_odm
|
||||
@@ -1113,6 +1139,60 @@ def test_export_keeps_conflict_when_odm_scope_cannot_decide(app, tmp_path):
|
||||
generate_shipment_excel(task)
|
||||
|
||||
|
||||
def test_export_released_shortage_only_notice_resolves_source_and_rows(app, tmp_path):
|
||||
"""整单短缺放行(0 条 matched 事实)也能解析库存源并按放行证据导出。
|
||||
|
||||
回归 OT-20261027-4BD4CEFF:预约键 0 命中→料号兜底自动放行后,行事实恒为
|
||||
not_found;_notice_source_code 只认 matched 会让整单放行的单报
|
||||
「库存源不存在或已停用」;prepare_export_match_inputs 的放行决定 join 须按
|
||||
confirmed_task_id(OT) 回链,Notice 身份调用不得丢放行行。
|
||||
"""
|
||||
from app.services.shipping_notice.export import _notice_source_code, prepare_export_match_inputs
|
||||
|
||||
app.config['SHIPPING_NOTICE_STORAGE_ROOT'] = str(tmp_path / 'shipping')
|
||||
with app.app_context():
|
||||
notice, _customer = _build_multi_odm_notice(
|
||||
tmp_path=tmp_path, released_shortage=True,
|
||||
order_part='PN-GONE', inventory_part='PN-OTHER', odm_values=['ODM-1'],
|
||||
)
|
||||
|
||||
# 断言意图 1:源解析把放行行事实与 matched 行同票,整单放行也能拿到唯一源。
|
||||
assert _notice_source_code(notice) == 'ODMSCOPE'
|
||||
|
||||
# 断言意图 2:以 Notice 身份准备导出输入,放行决定经 OT 回链可查到,
|
||||
# 放行行进入导出行集并携带审计补录值(无 matched 事实也不报「没有匹配」)。
|
||||
inputs = prepare_export_match_inputs(notice)
|
||||
assert inputs['released_snapshot_line_ids']
|
||||
assert inputs['released_export_line_indexes'] == {0}
|
||||
assert list(inputs['release_overrides_by_line'][0].values()) == ['ODM-1']
|
||||
assert [row['__order_line_index'] for row in inputs['line_values']] == [0]
|
||||
|
||||
# 断言意图 3:整单放行时证据快照仍落 Artifact 审计(matched-only 不再断证据链)。
|
||||
assert inputs['verification'] is not None
|
||||
|
||||
path, _filename_value, _artifact = generate_shipment_excel(notice)
|
||||
workbook = load_workbook(path, data_only=True)
|
||||
try:
|
||||
assert workbook['Detail'].cell(2, 1).value == 'ODM-1'
|
||||
finally:
|
||||
workbook.close()
|
||||
|
||||
|
||||
def test_unreleased_shortage_notice_still_lacks_source(app, tmp_path):
|
||||
"""未放行的短缺行不得参与源解析:matched-only 语义对未放行场景保持不变。"""
|
||||
from app.services.shipping_notice.export import _notice_source_code
|
||||
|
||||
app.config['SHIPPING_NOTICE_STORAGE_ROOT'] = str(tmp_path / 'shipping')
|
||||
with app.app_context():
|
||||
notice, _customer = _build_multi_odm_notice(
|
||||
tmp_path=tmp_path, unreleased_shortage=True,
|
||||
order_part='PN-GONE', inventory_part='PN-OTHER', odm_values=['ODM-1'],
|
||||
)
|
||||
|
||||
# 断言意图:not_found 且无放行决定的事实不充当导出源依据(fail-closed 不变)。
|
||||
assert _notice_source_code(notice) is None
|
||||
|
||||
|
||||
def test_notice_odm_options_and_choice_roundtrip(app, tmp_path):
|
||||
"""整单候选按客户范围逐行投影;合法选择落库并回显,非法选择有明确错误。"""
|
||||
from app.core.errors import AppError
|
||||
|
||||
Reference in new issue
Block a user