feat(shipping-notice): 添加识别定义和规则集管理功能,支持客户和站点的可配置识别规则

This commit is contained in:
hugo committed 2026-07-20 19:28:17 +08:00
1 parent 88408490d7
commit 34d489a2d1
167 files changed
+10365 -7978

No files matched your search

+35 -6
View File
@@ -23,7 +23,7 @@ from app.models import (
from app.services.shipping_notice import excel_template
from app.services.shipping_notice.export import _filename, _system_fact, generate_shipment_excel
from app.services.shipping_notice.fulfillment_workflow import _commit_generated_export
from app.core.errors import ValidationError
from app.core.errors import ConflictError, ValidationError
def _inventory_field_id(field_code: str) -> str:
@@ -132,7 +132,7 @@ def test_published_template_generates_dynamic_artifact(app, tmp_path):
source = ShippingInventorySource(
source_code='DUB', display_name='Dublin', connector_type='dbs', rpa_profile_id=login.id,
parsing_profile_id=parsing.id, excel_template_id=published['id'], warehouse_resolution_mode='fixed',
fixed_warehouse_id='DUB', report_path_json={}, query_parameters_json=[], match_aliases_json=[],
fixed_warehouse_id='DUB', report_path_json={}, query_parameters_json=[],
)
extraction = ShippingOrderExtraction(schema_version_id=version.id, input_snapshot_hash='i' * 64, status='accepted')
db.session.add_all([source, extraction])
@@ -242,7 +242,7 @@ def test_two_sources_can_share_one_published_excel_template(app, tmp_path):
source_code=code, display_name=code, connector_type='dbs', rpa_profile_id=login.id,
parsing_profile_id=parsing.id, excel_template_id=published['id'],
warehouse_resolution_mode='fixed', fixed_warehouse_id=code,
report_path_json={}, query_parameters_json=[], match_aliases_json=[],
report_path_json={}, query_parameters_json=[],
))
db.session.commit()
@@ -272,7 +272,7 @@ def test_disabled_source_still_blocks_template_retirement(app):
source_code='DISABLED_REF', display_name='Disabled Ref', connector_type='dbs', enabled=False,
rpa_profile_id=login.id, excel_template_id=published['id'],
warehouse_resolution_mode='fixed', fixed_warehouse_id='DUB',
report_path_json={}, query_parameters_json=[], match_aliases_json=[],
report_path_json={}, query_parameters_json=[],
))
db.session.commit()
@@ -313,7 +313,7 @@ def test_export_matches_inventory_by_profile_keys_not_row_position(app, tmp_path
db.session.add(ShippingInventorySource(
source_code='KEYED', display_name='Keyed', connector_type='dbs', rpa_profile_id=login.id,
parsing_profile_id=parsing.id, excel_template_id=published['id'], warehouse_resolution_mode='fixed',
fixed_warehouse_id='DUB', report_path_json={}, query_parameters_json=[], match_aliases_json=[],
fixed_warehouse_id='DUB', report_path_json={}, query_parameters_json=[],
))
extraction = ShippingOrderExtraction(schema_version_id=version.id, input_snapshot_hash='i' * 64, status='accepted')
db.session.add(extraction); db.session.flush()
@@ -377,6 +377,35 @@ def test_existing_template_can_create_new_draft_version_without_reupload(app):
assert set(layout['sheets']) == {'Header', 'Detail'}
def test_existing_template_can_clone_as_independent_v1_without_reupload(app):
"""复制为新模板必须复用文件和定义,但采用新编码且不加入原模板版本链。"""
with app.app_context():
draft = excel_template.create_draft(_workbook_upload(), {
'template_code': 'SOURCE_TEMPLATE', 'display_name': 'Source Template',
'definition': {'filename_pattern': '{business_no}.xlsx', 'mappings': [{
'sheet': 'Header', 'row_mode': 'header', 'start_row': 1, 'target_column': 1,
'source_kind': 'constant', 'source_key': 'copy', 'formatter': 'text',
}]},
}, actor_id=None)
published = excel_template.publish(draft['id'], actor_id=None)
copied = excel_template.clone_as_new_template(published['id'], {
'template_code': 'COPIED_TEMPLATE', 'display_name': 'Copied Template',
}, actor_id=None)
assert copied['template_code'] == 'COPIED_TEMPLATE'
assert copied['display_name'] == 'Copied Template'
assert copied['version'] == 1
assert copied['status'] == 'draft'
assert copied['definition'] == draft['definition']
assert copied['file_checksum'] == draft['file_checksum']
with pytest.raises(ConflictError) as exc_info:
excel_template.clone_as_new_template(published['id'], {
'template_code': 'COPIED_TEMPLATE', 'display_name': 'Another Copy',
}, actor_id=None)
assert exc_info.value.code == 'SHIPPING.EXCEL_TEMPLATE_CODE_EXISTS'
def test_template_publish_rejects_order_field_removed_from_current_schema(app):
"""模板草稿不得在订单字段移出当前 published Schema 后继续发布。"""
from app.services.shipping_notice.order_schema import service as order_schema_service
@@ -449,7 +478,7 @@ def test_export_rejects_ambiguous_inventory_values_and_cleans_partial_file(app,
db.session.add(ShippingInventorySource(
source_code='AMBIGUOUS', display_name='Ambiguous', connector_type='dbs', rpa_profile_id=login.id,
parsing_profile_id=parsing.id, excel_template_id=published['id'], warehouse_resolution_mode='fixed',
fixed_warehouse_id='DUB', report_path_json={}, query_parameters_json=[], match_aliases_json=[],
fixed_warehouse_id='DUB', report_path_json={}, query_parameters_json=[],
))
extraction = ShippingOrderExtraction(schema_version_id=version.id, input_snapshot_hash='i' * 64, status='accepted')
db.session.add(extraction); db.session.flush()