feat(shipping-notice): 增强订单文档 Profile 管理功能,新增复核与草稿管理
- 添加订单复核相关模型及 API,支持复核案例的创建、更新和确认 - 实现复核草稿的管理功能,允许用户对复核内容进行编辑和保存 - 引入复核事件审计,确保复核过程的可追溯性 - 更新数据库模型以支持复核和草稿的关系管理 - 完善相关服务逻辑,确保复核与草稿的状态管理和数据一致性 - 增强文档模板的管理能力,支持更复杂的业务场景
This commit is contained in:
1 parent
61ac6403c4
commit
b7307fc573
147 files changed
+15108
-1522
No files matched your search
@@ -114,6 +114,8 @@ def _published_profile_with_samples() -> tuple[ShippingOrderDocumentProfile, Use
|
||||
|
||||
def _publishable_v2_draft(profile: ShippingOrderDocumentProfile) -> None:
|
||||
"""将质量夹具改为最小 v2 草稿,使发布测试只覆盖阶段 4 边界。"""
|
||||
from app.services.shipping_notice import order_document_profile_service as profiles
|
||||
|
||||
profile.status = 'draft'
|
||||
profile.checksum = None
|
||||
profile.published_at = None
|
||||
@@ -135,6 +137,11 @@ def _publishable_v2_draft(profile: ShippingOrderDocumentProfile) -> None:
|
||||
}],
|
||||
}],
|
||||
}
|
||||
profile.definition_json = profiles._normalize_definition(
|
||||
profile.definition_json,
|
||||
schema_version=profile.schema_version,
|
||||
)
|
||||
profile.structure_fingerprint = profiles._definition_hash(profile.definition_json)
|
||||
|
||||
|
||||
def test_profile_blind_test_approval_enables_current_auto_freeze_qualification(app):
|
||||
@@ -297,13 +304,23 @@ def test_profile_checksum_change_invalidates_approved_quality_credential(app):
|
||||
assert not quality.profile_is_auto_create_approved(profile_id=profile.id, checksum=profile.checksum)
|
||||
|
||||
|
||||
def test_profile_auto_freeze_qualification_can_be_suspended_independently(app):
|
||||
def test_profile_auto_freeze_qualification_can_be_suspended_independently(app, monkeypatch):
|
||||
"""关键断言:暂停资格不退役模板,且只影响当前版本。"""
|
||||
from app.services.shipping_notice import order_document_profile_service as profiles
|
||||
|
||||
with app.app_context():
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.document_profile_quality_service.assert_profile_publishable', lambda _profile: None,
|
||||
)
|
||||
profile, user, _documents = _published_profile_with_samples()
|
||||
_publishable_v2_draft(profile)
|
||||
db.session.add(ShippingOrderDocumentProfileSample(
|
||||
profile_id=profile.id,
|
||||
document_id=_documents[0].id,
|
||||
table_id='table-1',
|
||||
sample_role='training',
|
||||
created_by_id=user.id,
|
||||
))
|
||||
db.session.commit()
|
||||
published = profiles.publish(profile.id, actor_id=user.id, expected_lock_version=profile.lock_version)
|
||||
qualification = quality.suspend_auto_freeze_qualification(
|
||||
@@ -314,13 +331,23 @@ def test_profile_auto_freeze_qualification_can_be_suspended_independently(app):
|
||||
assert published['auto_freeze_qualification']['status'] == 'manual_confirmation'
|
||||
|
||||
|
||||
def test_profile_auto_freeze_scope_can_be_configured_independently(app):
|
||||
def test_profile_auto_freeze_scope_can_be_configured_independently(app, monkeypatch):
|
||||
"""关键断言:客户/业务场景授权范围可独立配置,并写入模板审计摘要。"""
|
||||
from app.services.shipping_notice import order_document_profile_service as profiles
|
||||
|
||||
with app.app_context():
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.document_profile_quality_service.assert_profile_publishable', lambda _profile: None,
|
||||
)
|
||||
profile, user, _documents = _published_profile_with_samples()
|
||||
_publishable_v2_draft(profile)
|
||||
db.session.add(ShippingOrderDocumentProfileSample(
|
||||
profile_id=profile.id,
|
||||
document_id=_documents[0].id,
|
||||
table_id='table-1',
|
||||
sample_role='training',
|
||||
created_by_id=user.id,
|
||||
))
|
||||
db.session.commit()
|
||||
published = profiles.publish(profile.id, actor_id=user.id, expected_lock_version=profile.lock_version)
|
||||
customer = ShippingCustomer(standard_name='Scope Customer', short_code='SCOP')
|
||||
@@ -402,8 +429,8 @@ def test_blind_test_sample_removal_is_audited_and_approved_suite_is_immutable(ap
|
||||
assert getattr(caught.value, 'code', None) == 'SHIPPING.ORDER_DOCUMENT_PROFILE_TEST_IMMUTABLE'
|
||||
|
||||
|
||||
def test_draft_publish_is_independent_from_blind_test_and_starts_manual_confirmation(app):
|
||||
"""关键断言:模板可先发布供人工确认使用,缺样本绝不反向启用自动冻结。"""
|
||||
def test_draft_publish_requires_current_approved_blind_test(app):
|
||||
"""关键断言:阶段 7 起,缺少当前 approved blind test 的草稿不得发布。"""
|
||||
from app.services.shipping_notice import order_document_profile_service as profiles
|
||||
|
||||
with app.app_context():
|
||||
@@ -414,10 +441,9 @@ def test_draft_publish_is_independent_from_blind_test_and_starts_manual_confirma
|
||||
))
|
||||
db.session.commit()
|
||||
|
||||
published_without_suite = profiles.publish(profile.id, actor_id=user.id, expected_lock_version=profile.lock_version)
|
||||
assert published_without_suite['status'] == 'published'
|
||||
assert published_without_suite['auto_freeze_qualification']['status'] == 'manual_confirmation'
|
||||
assert not published_without_suite['auto_freeze_qualification']['auto_freeze_enabled']
|
||||
with pytest.raises(Exception) as caught:
|
||||
profiles.publish(profile.id, actor_id=user.id, expected_lock_version=profile.lock_version)
|
||||
assert getattr(caught.value, 'code', None) == 'SHIPPING.ORDER_DOCUMENT_PROFILE_PUBLISH_GATE_BLIND_TEST'
|
||||
|
||||
|
||||
def test_coordinate_v2_publish_promotes_approved_independent_suite(app):
|
||||
@@ -448,6 +474,11 @@ def test_coordinate_v2_publish_promotes_approved_independent_suite(app):
|
||||
}],
|
||||
}],
|
||||
}
|
||||
profile.definition_json = profiles._normalize_definition(
|
||||
profile.definition_json,
|
||||
schema_version=profile.schema_version,
|
||||
)
|
||||
profile.structure_fingerprint = profiles._definition_hash(profile.definition_json)
|
||||
|
||||
def set_coordinate_rows(document: ShippingNoticeDocument, rows: list[tuple[str, str]]) -> None:
|
||||
"""冻结每个样本的字符坐标,让 v2 盲测不依赖 HTML 网格。"""
|
||||
@@ -467,7 +498,6 @@ def test_coordinate_v2_publish_promotes_approved_independent_suite(app):
|
||||
|
||||
for document in documents:
|
||||
set_coordinate_rows(document, [('PN-1', '3')])
|
||||
set_coordinate_rows(documents[1], [('PN-1', '3'), ('PN-2', '4')])
|
||||
extra = ShippingNoticeDocument(
|
||||
intake_id=documents[2].intake_id, asset_id=documents[2].asset_id, document_type='attachment',
|
||||
attachment_key='quality-v2-extra.pdf', filename='quality-v2-extra.pdf', content_hash='f' * 64,
|
||||
@@ -487,7 +517,7 @@ def test_coordinate_v2_publish_promotes_approved_independent_suite(app):
|
||||
quality.add_sample(suite_id=suite['id'], document_id=documents[0].id, table_id='table-1', expected_rows=[{'part_number': 'PN-1', 'qty': '3'}], actor_id=user.id)
|
||||
assert getattr(reused.value, 'code', None) == 'SHIPPING.ORDER_DOCUMENT_PROFILE_TEST_SAMPLE_NOT_INDEPENDENT'
|
||||
quality.add_sample(suite_id=suite['id'], document_id=documents[1].id, table_id='table-1', expected_rows=[
|
||||
{'line_no': '00010', 'part_number': 'PN-1', 'qty': '3'}, {'line_no': '00020', 'part_number': 'PN-2', 'qty': '4'},
|
||||
{'line_no': '00010', 'part_number': 'PN-1', 'qty': '3'},
|
||||
], actor_id=user.id)
|
||||
quality.add_sample(suite_id=suite['id'], document_id=documents[2].id, table_id='table-1', expected_rows=[{'line_no': '00010', 'part_number': 'PN-1', 'qty': '3'}], actor_id=user.id)
|
||||
quality.add_sample(suite_id=suite['id'], document_id=extra.id, table_id='table-1', expected_rows=[{'line_no': '00010', 'part_number': 'PN-3', 'qty': '5'}], actor_id=user.id)
|
||||
@@ -499,3 +529,6 @@ def test_coordinate_v2_publish_promotes_approved_independent_suite(app):
|
||||
assert published['status'] == 'published'
|
||||
assert published['auto_freeze_qualification']['status'] == 'manual_confirmation'
|
||||
assert not quality.profile_is_auto_create_approved(profile_id=profile.id, checksum=published['checksum'])
|
||||
frozen_suite = db.session.get(ShippingDocumentProfileTestSuite, suite['id'])
|
||||
assert frozen_suite.profile_checksum == published['checksum']
|
||||
assert all(run.profile_checksum == published['checksum'] for run in frozen_suite.runs)
|
||||
Reference in new issue
Block a user