feat(shipping-notice): 完善订单解析、模板管理与库存 RPA 流程
- 优化订单文档解析、补充合并与坐标重建 - 完善订单模板校验、发布及前端管理界面 - 改进库存 RPA 下载回退与工作流处理 - 补充后端、前端及 RPA 自动化测试 - 更新 Shipping Notice 技术文档与四语言文案
This commit is contained in:
1 parent
c4a27324c8
commit
8f2f568f92
46 files changed
+1745
-265
No files matched your search
@@ -8,6 +8,8 @@ from app.services.shipping_notice.reservation_region import (
|
||||
apply_reservation_region_candidates,
|
||||
extract_reservation_from_region_text,
|
||||
extract_reservation_from_vendor_comments_pages,
|
||||
project_reservation_onto_validation_evidence,
|
||||
reservation_region_candidates_from_layout,
|
||||
)
|
||||
|
||||
|
||||
@@ -106,8 +108,23 @@ def test_vendor_comments_window_crosses_pages_and_stops_at_first_terms_heading()
|
||||
assert [item['value'] for item in candidates] == ['33008', '3000098851']
|
||||
|
||||
|
||||
def test_terms_heading_matches_when_phrase_is_only_part_of_title():
|
||||
"""结束锚点只需标题含 Terms and Conditions,不要求整行仅有该短语。"""
|
||||
candidates, reason = extract_reservation_from_vendor_comments_pages([
|
||||
(1, _glyph_lines(
|
||||
'Vendor Comments',
|
||||
'DBS Reservation Line 1: 1000143920',
|
||||
'7. Terms and Conditions of Sale',
|
||||
'Reservation#99999',
|
||||
)),
|
||||
])
|
||||
|
||||
assert reason is None
|
||||
assert [item['value'] for item in candidates] == ['1000143920']
|
||||
|
||||
|
||||
def test_vendor_comments_window_requires_start_and_end_headings():
|
||||
"""缺少任一边界时不能把全文中的 Reservation 当作专区证据。"""
|
||||
"""缺少起始锚点时不得扫描全文;缺少结束锚点时仍返回窗内候选但必须带复核原因。"""
|
||||
candidates, reason = extract_reservation_from_vendor_comments_pages([
|
||||
(1, _glyph_lines('Reservation#33008')),
|
||||
])
|
||||
@@ -115,6 +132,18 @@ def test_vendor_comments_window_requires_start_and_end_headings():
|
||||
assert candidates == []
|
||||
assert reason == 'vendor_comments_anchor_missing'
|
||||
|
||||
open_candidates, open_reason = extract_reservation_from_vendor_comments_pages([
|
||||
(1, _glyph_lines(
|
||||
'Vendor Comments:',
|
||||
'DBS Reservation Line 1: 1000143920',
|
||||
'End Customer: D1',
|
||||
)),
|
||||
])
|
||||
assert open_reason == 'terms_and_conditions_anchor_missing'
|
||||
assert [item['value'] for item in open_candidates] == ['1000143920']
|
||||
assert open_candidates[0]['scope'] == 'line'
|
||||
assert open_candidates[0]['line_no'] == 1
|
||||
|
||||
|
||||
def test_reservation_region_applies_header_and_line_override_together():
|
||||
"""整单值是默认值,指定行的 Reservation 仅覆盖对应明细。"""
|
||||
@@ -165,3 +194,71 @@ def test_reservation_gate_blocks_empty_and_malformed_order_lines():
|
||||
|
||||
assert reservation_gate_issues([])[0]["reason"] == "missing_order_lines"
|
||||
assert reservation_gate_issues(["invalid-line"])[0]["reason"] == "invalid_order_line"
|
||||
|
||||
|
||||
def test_reservation_region_candidates_from_layout_requires_configured_region():
|
||||
"""未标注专区时不得扫描 Vendor Comments;标注后必须走锚点窗而非 page_no/region。"""
|
||||
layout = {
|
||||
'coordinate_evidence': {
|
||||
'pages': {'1': {'width': 800, 'height': 600}},
|
||||
'page_glyphs': {
|
||||
'1': _glyph_lines(
|
||||
'Vendor Comments:',
|
||||
'DBS Reservation Line 1: 1000143920',
|
||||
'Terms and Conditions:',
|
||||
),
|
||||
},
|
||||
},
|
||||
}
|
||||
assert reservation_region_candidates_from_layout(definition={}, layout=layout) == {
|
||||
'candidates': [], 'reason': None,
|
||||
}
|
||||
result = reservation_region_candidates_from_layout(
|
||||
definition={'reservation_id_region': {'page_no': 9, 'region': {'x0': 0, 'y0': 0, 'x1': 1, 'y1': 1}}},
|
||||
layout=layout,
|
||||
)
|
||||
assert result['reason'] is None
|
||||
assert [item['value'] for item in result['candidates']] == ['1000143920']
|
||||
assert result['candidates'][0]['scope'] == 'line'
|
||||
assert result['candidates'][0]['line_no'] == 1
|
||||
|
||||
|
||||
def test_project_reservation_onto_validation_evidence_writes_line_and_review_reason():
|
||||
"""验证证据必须落入与正式解析相同的 header/line 字段,并保留锚点缺失原因。"""
|
||||
evidence = {
|
||||
'header_fields': [{
|
||||
'field_id': 'f-po', 'field_code': 'customer_po_number', 'raw_value': 'PO-1',
|
||||
'normalized_value': 'PO-1', 'status': 'passed', 'issues': [],
|
||||
}],
|
||||
'lines': [{'row_index': 0, 'fields': [{
|
||||
'field_id': 'f-part', 'field_code': 'part_number', 'raw_value': 'P-1',
|
||||
'normalized_value': 'P-1', 'status': 'passed', 'issues': [],
|
||||
}]}],
|
||||
'cross_checks': {},
|
||||
}
|
||||
projected = project_reservation_onto_validation_evidence(
|
||||
evidence,
|
||||
candidates=[{
|
||||
'value': '1000143920', 'line_no': 1, 'scope': 'line',
|
||||
'raw_text': 'DBS Reservation Line 1: 1000143920', 'status': 'mapped',
|
||||
}],
|
||||
reason=None,
|
||||
schema_fields={
|
||||
'header-reservation': {
|
||||
'field_id': 'header-reservation', 'field_code': 'reservation_id', 'scope': 'header',
|
||||
},
|
||||
'line-reservation': {
|
||||
'field_id': 'line-reservation', 'field_code': 'reservation_id', 'scope': 'line',
|
||||
},
|
||||
},
|
||||
)
|
||||
assert projected['lines'][0]['fields'][-1] == {
|
||||
'field_id': 'line-reservation', 'field_code': 'reservation_id',
|
||||
'raw_value': '1000143920', 'normalized_value': '1000143920',
|
||||
'status': 'passed', 'issues': [],
|
||||
}
|
||||
missing = project_reservation_onto_validation_evidence(
|
||||
evidence, candidates=[], reason='vendor_comments_anchor_missing', schema_fields={},
|
||||
)
|
||||
assert missing['reservation_region_status'] == 'needs_review'
|
||||
assert missing['reservation_region_review_reasons'] == ['vendor_comments_anchor_missing']
|
||||
Reference in new issue
Block a user