feat(shipping-notice): 实现滚动履约功能,优化发货通知流程与代码清理
清理废弃的ShippingCase相关代码与依赖,统一使用ShippingNotice直接关联客户数据。调整库存网关依赖规则,支持仅对库存满足或已人工放行的订单行生成发货Excel,实现滚动履约逻辑。
This commit is contained in:
1 parent
7cfd5d167e
commit
1e5aedb9ed
235 files changed
+11394
-9613
No files matched your search
@@ -19,7 +19,7 @@ from app import db
|
||||
from app.models import (
|
||||
ShippingExcelTemplate, ShippingInventoryParsingProfile, ShippingInventorySource, ShippingOrderExtraction,
|
||||
ShippingOrderField, ShippingOrderFieldDecision, ShippingOrderFieldValue, ShippingOrderLine,
|
||||
ShippingCase, ShippingInventoryField, ShippingInventoryFile, ShippingOrderSchema, ShippingOrderSchemaVersion,
|
||||
ShippingCustomer, ShippingInventoryField, ShippingInventoryFile, ShippingOrderSchema, ShippingOrderSchemaVersion,
|
||||
ShippingOrderSnapshot, ShippingOrderSnapshotLine, ShippingRpaProfile, ShippingNotice,
|
||||
)
|
||||
from app.services.shipping_notice import excel_template
|
||||
@@ -152,12 +152,10 @@ def _workbook_upload() -> FileStorage:
|
||||
|
||||
def test_filename_pattern_supports_business_number_and_split_business_variables():
|
||||
"""业务单号与客户日期流水变量均从业务单快照渲染,不能依赖当前客户主数据。"""
|
||||
shipping_case = ShippingCase(
|
||||
case_no='CASE-FILENAME', business_no='WYC26060201', customer_short_code_snapshot='WYC',
|
||||
business_date=date(2026, 6, 2), sequence_value=1,
|
||||
task = ShippingNotice(
|
||||
task_no='TASK-FILENAME', inventory_source_code='DBS', business_no='WYC26060201',
|
||||
customer_short_code_snapshot='WYC', business_date=date(2026, 6, 2), business_sequence_value=1,
|
||||
)
|
||||
task = ShippingNotice(task_no='TASK-FILENAME', inventory_source_code='DBS')
|
||||
task.shipping_case = shipping_case
|
||||
template = ShippingExcelTemplate(
|
||||
template_code='FILENAME', display_name='Filename',
|
||||
definition_json={'filename_pattern': '{business_no}_{customer_short_code}{business_date}{sequence}_{source_code}.xlsx'},
|
||||
@@ -333,8 +331,15 @@ def test_published_template_generates_dynamic_artifact(app, tmp_path):
|
||||
ShippingOrderFieldValue(extraction_id=extraction.id, field_id=po_number.id, value_text='16754796', decision_id=po_decision.id),
|
||||
ShippingOrderFieldValue(extraction_id=extraction.id, line_id=order_line.id, field_id=part.id, value_text='PN-1', decision_id=line_decision.id),
|
||||
])
|
||||
confirmed_customer = ShippingCustomer(
|
||||
standard_name='Export ACME', short_code='EAC', status='active',
|
||||
)
|
||||
db.session.add(confirmed_customer)
|
||||
db.session.flush()
|
||||
task = ShippingNotice(
|
||||
task_no='TASK-EXPORT-1', current_order_extraction_id=extraction.id, inventory_source_code='DUB',
|
||||
customer_id=confirmed_customer.id,
|
||||
customer_resolution_status='confirmed',
|
||||
# 此模板只消费 ODM 等 inventory_field;任务级 Warehouse ID 缺失不应阻断导出。
|
||||
inventory_warehouse_id=None, inventory_lines_json=[{
|
||||
_inventory_field_id('part_number'): 'PN-1', _inventory_field_id('odm_id'): 'ODM-9',
|
||||
@@ -348,6 +353,7 @@ def test_published_template_generates_dynamic_artifact(app, tmp_path):
|
||||
lines=[(1, part.id, 'PN-1', 1, '1000000001')],
|
||||
)
|
||||
|
||||
assert task.business_no is None
|
||||
path, filename, artifact = generate_shipment_excel(task)
|
||||
db.session.commit()
|
||||
|
||||
@@ -363,10 +369,13 @@ def test_published_template_generates_dynamic_artifact(app, tmp_path):
|
||||
assert artifact.order_schema_version_id == version.id
|
||||
assert artifact.inventory_parsing_profile_id == parsing.id
|
||||
assert artifact.file_checksum and artifact.input_checksum and artifact.file_size > 0
|
||||
assert task.business_no is not None
|
||||
assert task.business_no.startswith('EAC')
|
||||
|
||||
# 已存在待上传 Artifact 时仍保持原有幂等保护,和 Warehouse ID 无关。
|
||||
with pytest.raises(ValueError, match='当前任务存在待上传的发货 Excel'):
|
||||
# 一个 Notice 已有 Excel 后必须创建新 Notice,禁止同号追加第二个 Artifact。
|
||||
with pytest.raises(ConflictError) as second_export:
|
||||
generate_shipment_excel(task)
|
||||
assert second_export.value.code == 'SHIPPING.NOTICE_EXCEL_ALREADY_GENERATED'
|
||||
|
||||
|
||||
def test_header_mapping_rejects_line_order_field(app):
|
||||
@@ -401,17 +410,13 @@ def test_export_date_system_fact_uses_business_timezone(app):
|
||||
assert isinstance(value, date)
|
||||
|
||||
|
||||
def test_excel_pull_request_number_uses_export_date_without_changing_case_number(app):
|
||||
"""Excel Pull Request Number 必须采用导出日期,且业务单主编号保持原值。"""
|
||||
def test_excel_pull_request_number_uses_notice_business_number(app):
|
||||
"""Excel Pull Request Number 直接使用 Notice business_no,不因导出日期重编号。"""
|
||||
with app.app_context():
|
||||
shipping_case = ShippingCase(
|
||||
case_no='CASE-EXCEL-NO', business_no='IVMX26080801', sequence_value=1,
|
||||
)
|
||||
task = ShippingNotice(task_no='TASK-EXCEL-NO')
|
||||
task.shipping_case = shipping_case
|
||||
task = ShippingNotice(task_no='TASK-EXCEL-NO', business_no='IVMX26080801', business_sequence_value=1)
|
||||
|
||||
assert _excel_business_no(task, export_date=date(2026, 8, 11)) == 'IVMX26081101'
|
||||
assert shipping_case.business_no == 'IVMX26080801'
|
||||
assert _excel_business_no(task, export_date=date(2026, 8, 11)) == 'IVMX26080801'
|
||||
assert task.business_no == 'IVMX26080801'
|
||||
|
||||
|
||||
def test_export_mapping_uses_sequence_but_never_derives_formal_line_amount(app):
|
||||
|
||||
Reference in new issue
Block a user