refactor(shipping-notice): 统一料号字段,移除过时的 SKU 相关字段,更新相关逻辑以支持新字段命名

This commit is contained in:
hugo committed 2026-07-16 20:02:33 +08:00
1 parent dde25344ca
commit 46eb63f5bb
111 files changed
+3116 -1250

No files matched your search

+114 -74
View File
@@ -64,7 +64,7 @@ def _parse_notice_for_stable_inventory_source(client, headers, task_id: str) ->
"structured": {
"customer_name": "AWS",
"ship_to": "Dublin",
"lines": [{"sku": "A001", "reservation_id": "AWS-311", "qty": 1, "uom": "EA"}],
"lines": [{"part_number": "A001", "reservation_id": "AWS-311", "qty": 1, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -121,12 +121,12 @@ def test_match_notice_lines_reports_progress():
status, line_results, shortage = match_notice_lines(
[
{"sku": "A001", "reservation_id": "R-1", "qty": 1},
{"sku": "A002", "reservation_id": "R-2", "qty": 2},
{"part_number": "A001", "reservation_id": "R-1", "qty": 1},
{"part_number": "A002", "reservation_id": "R-2", "qty": 2},
],
[
{"sku": "A001", "reservation_id": "R-1", "available_qty": 1},
{"sku": "A002", "reservation_id": "R-2", "available_qty": 2},
{"part_number": "A001", "reservation_id": "R-1", "available_qty": 1},
{"part_number": "A002", "reservation_id": "R-2", "available_qty": 2},
],
progress_callback=lambda current, total: seen.append((current, total)),
)
@@ -158,11 +158,11 @@ def test_shipping_notice_tool_flow(app, client):
"structured": {
"customer_name": "ACME",
"lines": [{
"sku": "A001",
"part_number": "A001",
"reservation_id": "R-1",
"qty": 10,
"uom": "EA",
"source_type": "AWS Dublin",
"inventory_source_hint": "AWS Dublin",
}],
"confidence": 0.95,
},
@@ -172,14 +172,14 @@ def test_shipping_notice_tool_flow(app, client):
parse_body = parse_res.get_json()
assert parse_body["status"] in {"ok", "needs_human", "running"}
assert "【发货通知解析确认】" in parse_body["message"]
assert "| 料号 | A001 |" in parse_body["message"]
assert "| 内部料号 | A001 |" in parse_body["message"]
inv_res = client.post(
"/api/shipping-notice/tools/ensure_inventory",
headers=headers,
json={
"task_id": task_id,
"inventory_lines": [{"sku": "A001", "reservation_id": "R-1", "available_qty": 10}],
"inventory_lines": [{"part_number": "A001", "reservation_id": "R-1", "available_qty": 10}],
},
)
assert inv_res.status_code == 200
@@ -267,7 +267,7 @@ def test_shipping_notice_match_shortage_needs_human(app, client):
"task_id": task_id,
"structured": {
"customer_name": "ACME",
"lines": [{"sku": "A001", "reservation_id": "R-1", "qty": 100, "uom": "EA"}],
"lines": [{"part_number": "A001", "reservation_id": "R-1", "qty": 100, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -275,7 +275,7 @@ def test_shipping_notice_match_shortage_needs_human(app, client):
client.post(
"/api/shipping-notice/tools/ensure_inventory",
headers=headers,
json={"task_id": task_id, "inventory_lines": [{"sku": "A001", "reservation_id": "R-1", "available_qty": 5}]},
json={"task_id": task_id, "inventory_lines": [{"part_number": "A001", "reservation_id": "R-1", "available_qty": 5}]},
)
match_res = client.post(
"/api/shipping-notice/tools/match_inventory",
@@ -329,7 +329,7 @@ def test_submit_decision_rematch_reruns_match_and_returns_shortage(app, client,
"task_id": task_id,
"structured": {
"customer_name": "ACME",
"lines": [{"sku": "A001", "reservation_id": "R-1", "qty": 100, "uom": "EA"}],
"lines": [{"part_number": "A001", "reservation_id": "R-1", "qty": 100, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -337,7 +337,7 @@ def test_submit_decision_rematch_reruns_match_and_returns_shortage(app, client,
client.post(
"/api/shipping-notice/tools/ensure_inventory",
headers=headers,
json={"task_id": task_id, "inventory_lines": [{"sku": "A001", "reservation_id": "R-1", "available_qty": 5}]},
json={"task_id": task_id, "inventory_lines": [{"part_number": "A001", "reservation_id": "R-1", "available_qty": 5}]},
)
client.post(
"/api/shipping-notice/tools/match_inventory",
@@ -394,7 +394,7 @@ def test_contract_submit_decision_rematch_is_direct_recovery_entry(app, client,
"task_id": task_id,
"structured": {
"customer_name": "ACME",
"lines": [{"sku": "A001", "reservation_id": "R-1", "qty": 20, "uom": "EA"}],
"lines": [{"part_number": "A001", "reservation_id": "R-1", "qty": 20, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -402,7 +402,7 @@ def test_contract_submit_decision_rematch_is_direct_recovery_entry(app, client,
client.post(
"/api/shipping-notice/tools/ensure_inventory",
headers=headers,
json={"task_id": task_id, "inventory_lines": [{"sku": "A001", "reservation_id": "R-1", "available_qty": 1}]},
json={"task_id": task_id, "inventory_lines": [{"part_number": "A001", "reservation_id": "R-1", "available_qty": 1}]},
)
client.post(
"/api/shipping-notice/tools/match_inventory",
@@ -481,7 +481,7 @@ def test_confirm_inventory_source_route_returns_json(app, client):
process_status="pending_review",
pending_human_reason="inventory_source_unresolved",
ship_to="Dublin",
lines_json=[{"sku": "A001", "qty": 1, "reservation_id": "R1"}],
lines_json=[{"part_number": "A001", "qty": 1, "reservation_id": "R1"}],
)
db.session.add(task)
db.session.commit()
@@ -533,7 +533,7 @@ def test_parse_inventory_from_chat_text(app, client):
"task_id": task_id,
"structured": {
"customer_name": "ACME",
"lines": [{"sku": "A001", "reservation_id": "R-1", "qty": 10, "uom": "EA"}],
"lines": [{"part_number": "A001", "reservation_id": "R-1", "qty": 10, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -592,7 +592,7 @@ def test_parse_inventory_empty_needs_human(app, client):
assert body.get("human_options") is not None or body.get("action_buttons")
def test_match_by_aws_sku_and_reservation_id(app, client):
def test_match_by_supplier_sku_and_reservation_id(app, client):
headers = _tool_headers(app)
create_res = client.post(
"/api/shipping-notice/tools/create_task",
@@ -609,8 +609,8 @@ def test_match_by_aws_sku_and_reservation_id(app, client):
"structured": {
"customer_name": "AWS",
"lines": [
{"sku": "10-40594-001", "reservation_id": "AWS-311", "qty": 2, "uom": "EA"},
{"sku": "10-40594-001", "reservation_id": "ORD-3002", "qty": 1, "uom": "EA"},
{"part_number": "D4-A08AR12000002", "aws_part_number": "10-40594-001", "reservation_id": "AWS-311", "qty": 2, "uom": "EA"},
{"part_number": "D4-A08AR12000002", "aws_part_number": "10-40594-001", "reservation_id": "ORD-3002", "qty": 1, "uom": "EA"},
],
"confidence": 0.95,
},
@@ -618,9 +618,9 @@ def test_match_by_aws_sku_and_reservation_id(app, client):
)
inv_text = (
"AWS Sku\tCOM ID\tQty Available\n"
"10-40594-001\tAWS-311\t2\n"
"10-40594-001\tORD-3002\t0\n"
"Supplier Sku\tAWS Sku\tCOM ID\tQty Available\n"
"D4-A08AR12000002\t10-40594-001\tAWS-311\t2\n"
"D4-A08AR12000002\t10-40594-001\tORD-3002\t0\n"
)
client.post(
"/api/shipping-notice/tools/parse_inventory",
@@ -661,7 +661,7 @@ def test_match_inventory_blocked_before_mapping_confirm(app, client):
"task_id": task_id,
"structured": {
"customer_name": "AWS",
"lines": [{"sku": "10-40594-001", "reservation_id": "AWS-311", "qty": 1, "uom": "EA"}],
"lines": [{"part_number": "D4-A08AR12000002", "aws_part_number": "10-40594-001", "reservation_id": "AWS-311", "qty": 1, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -671,7 +671,7 @@ def test_match_inventory_blocked_before_mapping_confirm(app, client):
headers=headers,
json={
"task_id": task_id,
"raw_inventory_text": "AWS Sku\tCOM ID\tQty Available\n10-40594-001\tAWS-311\t1\n",
"raw_inventory_text": "Supplier Sku\tAWS Sku\tCOM ID\tQty Available\nD4-A08AR12000002\t10-40594-001\tAWS-311\t1\n",
},
)
@@ -686,7 +686,8 @@ def test_match_inventory_blocked_before_mapping_confirm(app, client):
assert blocked.get("stop_agent_turn") is True
assert "field_alignment" in blocked["data"]
mapping = blocked["data"]["field_alignment"]
assert mapping["inventory_columns"]["mapping"]["sku"]["source_column"] == "AWS Sku"
assert mapping["inventory_columns"]["mapping"]["part_number"]["source_column"] == "Supplier Sku"
assert mapping["inventory_columns"]["mapping"]["aws_part_number"]["source_column"] == "AWS Sku"
assert mapping["inventory_columns"]["mapping"]["reservation_id"]["source_column"] == "COM ID"
@@ -706,7 +707,7 @@ def test_match_inventory_requires_reservation_id(app, client):
"task_id": task_id,
"structured": {
"customer_name": "ACME",
"lines": [{"sku": "A001", "reservation_id": "R-1", "qty": 1, "uom": "EA"}],
"lines": [{"part_number": "A001", "reservation_id": "R-1", "qty": 1, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -714,7 +715,7 @@ def test_match_inventory_requires_reservation_id(app, client):
with app.app_context():
task = ShippingTask.query.filter_by(task_no=task_id).first()
assert task is not None
task.lines_json = [{"sku": "A001", "qty": 1, "uom": "EA"}]
task.lines_json = [{"part_number": "A001", "qty": 1, "uom": "EA"}]
db.session.commit()
from app.services.shipping_notice.inventory_workflow import (
ensure_inventory as ensure_inventory_service,
@@ -726,7 +727,7 @@ def test_match_inventory_requires_reservation_id(app, client):
direct_data = ensure_inventory_service({
"task_id": task_id,
"inventory_lines": [{"sku": "A001", "reservation_id": "R-1", "available_qty": 10}],
"inventory_lines": [{"part_number": "A001", "reservation_id": "R-1", "available_qty": 10}],
})
assert direct_data["status"] == "needs_human", direct_data
assert direct_data.get("checkpoint") == "rsv_req"
@@ -734,7 +735,7 @@ def test_match_inventory_requires_reservation_id(app, client):
parse_data = parse_inventory_service({
"task_id": task_id,
"inventory_lines": [{"sku": "A001", "reservation_id": "R-1", "available_qty": 10}],
"inventory_lines": [{"part_number": "A001", "reservation_id": "R-1", "available_qty": 10}],
})
assert parse_data["status"] == "needs_human"
assert parse_data.get("checkpoint") == "rsv_req"
@@ -771,7 +772,15 @@ def test_correct_inventory_mapping_resets_to_inference(app, client, tmp_path):
"task_id": task_id,
"structured": {
"customer_name": "AWS",
"lines": [{"sku": "10-40594-001", "reservation_id": "AWS-311", "qty": 1, "uom": "EA"}],
"lines": [
{
"part_number": "D4-A08AR12000002",
"aws_part_number": "10-40594-001",
"reservation_id": "AWS-311",
"qty": 1,
"uom": "EA",
}
],
"confidence": 0.95,
},
},
@@ -781,7 +790,10 @@ def test_correct_inventory_mapping_resets_to_inference(app, client, tmp_path):
headers=headers,
json={
"task_id": task_id,
"raw_inventory_text": "AWS Sku\tCOM ID\tQty Available\n10-40594-001\tAWS-311\t1\n",
"raw_inventory_text": (
"Supplier Sku\tAWS Sku\tCOM ID\tQty Available\n"
"D4-A08AR12000002\t10-40594-001\tAWS-311\t1\n"
),
},
)
@@ -795,7 +807,12 @@ def test_correct_inventory_mapping_resets_to_inference(app, client, tmp_path):
assert data.get("checkpoint") == "map_infer"
assert data.get("stop_agent_turn") is True
assert "schema_preview" in data["data"]
assert data["data"]["schema_preview"]["headers"] == ["AWS Sku", "COM ID", "Qty Available"]
assert data["data"]["schema_preview"]["headers"] == [
"Supplier Sku",
"AWS Sku",
"COM ID",
"Qty Available",
]
def test_rpa_inventory_callback(app, client, tmp_path, monkeypatch):
@@ -813,6 +830,25 @@ def test_rpa_inventory_callback(app, client, tmp_path, monkeypatch):
json={"source_type": "manual"},
)
task_id = create_res.get_json()["task_id"]
client.post(
"/api/shipping-notice/tools/parse_notice",
headers=headers,
json={
"task_id": task_id,
"structured": {
"customer_name": "ACME",
"lines": [
{
"part_number": "A001",
"reservation_id": "R-1",
"qty": 1,
"uom": "EA",
}
],
"confidence": 0.95,
},
},
)
from app import db
from tests.conftest import seed_task_inventory_source
@@ -829,8 +865,8 @@ def test_rpa_inventory_callback(app, client, tmp_path, monkeypatch):
inv_file = drop / "stock.xlsx"
wb = Workbook()
ws = wb.active
ws.append(["Warehouse ID", "料号", "可用数量"])
ws.append(["AWSDU", "A001", 20])
ws.append(["Warehouse ID", "Supplier Sku", "Reservation ID", "可用数量"])
ws.append(["AWSDU", "A001", "R-1", 20])
wb.save(inv_file)
wb.close()
@@ -842,8 +878,8 @@ def test_rpa_inventory_callback(app, client, tmp_path, monkeypatch):
"task_no": task_id,
"success": True,
"file_path": str(inv_file),
"run_no": "RUN-TOOLS-CB",
"source_code": "DSV360_AWSDU",
"run_no": "RUN-TOOLS-CB",
"source_code": "DSV360_AWSDU",
"site_id": "AWSDU",
"warehouse_id": "AWSDU",
}
@@ -880,7 +916,7 @@ def test_rpa_upload_callback(app, client, tmp_path):
"task_id": task_id,
"structured": {
"customer_name": "ACME",
"lines": [{"sku": "A001", "reservation_id": "R-1", "qty": 5, "uom": "EA"}],
"lines": [{"part_number": "A001", "reservation_id": "R-1", "qty": 5, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -888,7 +924,7 @@ def test_rpa_upload_callback(app, client, tmp_path):
client.post(
"/api/shipping-notice/tools/ensure_inventory",
headers=headers,
json={"task_id": task_id, "inventory_lines": [{"sku": "A001", "reservation_id": "R-1", "available_qty": 10}]},
json={"task_id": task_id, "inventory_lines": [{"part_number": "A001", "reservation_id": "R-1", "available_qty": 10}]},
)
client.post(
"/api/shipping-notice/tools/match_inventory",
@@ -911,7 +947,7 @@ def test_rpa_upload_callback(app, client, tmp_path):
assert cb_res.get_json()["data"]["freight_ref_no"] == "FR-001"
def test_generate_shipment_excel_writes_vendor_part_and_odm_id(app, client):
def test_generate_shipment_excel_writes_part_number_and_odm_id(app, client):
headers = _tool_headers(app)
create_res = client.post(
@@ -931,8 +967,7 @@ def test_generate_shipment_excel_writes_vendor_part_and_odm_id(app, client):
"po_number": "SN-20260608-7FCBFA4B",
"lines": [
{
"sku": "504-010213-001",
"vendor_part_number": "504-010213-001",
"part_number": "504-010213-001",
"reservation_id": "1000140351",
"qty": 9,
"uom": "EA",
@@ -949,7 +984,7 @@ def test_generate_shipment_excel_writes_vendor_part_and_odm_id(app, client):
"task_id": task_id,
"inventory_lines": [
{
"sku": "504-010213-001",
"part_number": "504-010213-001",
"reservation_id": "1000140351",
"available_qty": 9,
"odm_id": "16754796",
@@ -1004,7 +1039,7 @@ def test_upload_inventory_file_parses_server_side(app, client, tmp_path):
"task_id": task_id,
"structured": {
"customer_name": "AWS",
"lines": [{"sku": "10-40594-001", "reservation_id": "AWS-311", "qty": 1, "uom": "EA"}],
"lines": [{"part_number": "10-40594-001", "reservation_id": "AWS-311", "qty": 1, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -1017,8 +1052,8 @@ def test_upload_inventory_file_parses_server_side(app, client, tmp_path):
buf = BytesIO()
wb = Workbook()
ws = wb.active
ws.append(["Warehouse ID", "AWS Sku", "COM ID", "Qty Available"])
ws.append(["AWSDU", "10-40594-001", "AWS-311", 5])
ws.append(["Warehouse ID", "Supplier Sku", "AWS Sku", "COM ID", "Qty Available"])
ws.append(["AWSDU", "D4-A08AR12000002", "10-40594-001", "AWS-311", 5])
wb.save(buf)
wb.close()
buf.seek(0)
@@ -1036,8 +1071,9 @@ def test_upload_inventory_file_parses_server_side(app, client, tmp_path):
assert upload_data["status"] == "ok"
assert upload_data.get("checkpoint") == "map_infer"
preview = upload_data["data"]["schema_preview"]
assert preview["headers"] == ["Warehouse ID", "AWS Sku", "COM ID", "Qty Available"]
assert preview["suggested_mapping"]["sku"] == "AWS Sku"
assert preview["headers"] == ["Warehouse ID", "Supplier Sku", "AWS Sku", "COM ID", "Qty Available"]
assert preview["suggested_mapping"]["part_number"] == "Supplier Sku"
assert preview["suggested_mapping"]["aws_part_number"] == "AWS Sku"
apply_res = client.post(
"/api/shipping-notice/tools/apply_inventory_mapping",
@@ -1091,7 +1127,7 @@ def test_batch_inventory_upload_does_not_reopen_completed_task(app, client, tmp_
source_type="manual",
process_status="uploaded",
pending_human_reason=None,
lines_json=[{"sku": "A001", "reservation_id": "R-1", "qty": 1, "uom": "EA"}],
lines_json=[{"part_number": "A001", "reservation_id": "R-1", "qty": 1, "uom": "EA"}],
batch_index=1,
batch_total=2,
)
@@ -1100,7 +1136,7 @@ def test_batch_inventory_upload_does_not_reopen_completed_task(app, client, tmp_
batch=batch,
source_type="manual",
process_status="waiting_inventory",
lines_json=[{"sku": "A002", "reservation_id": "R-2", "qty": 1, "uom": "EA"}],
lines_json=[{"part_number": "A002", "reservation_id": "R-2", "qty": 1, "uom": "EA"}],
batch_index=2,
batch_total=2,
)
@@ -1156,8 +1192,8 @@ def test_apply_inventory_mapping_fallback_match_rule(app, client, tmp_path):
wb = Workbook()
ws = wb.active
ws.append(["Warehouse ID", "AWS Sku", "COM ID", "Qty Available"])
ws.append(["AWSDU", "504-010213-001", "1000140351", 5])
ws.append(["Warehouse ID", "Supplier Sku", "AWS Sku", "COM ID", "Qty Available"])
ws.append(["AWSDU", "D4-A08AR12000002", "504-010213-001", "1000140351", 5])
buf = BytesIO()
wb.save(buf)
buf.seek(0)
@@ -1174,7 +1210,7 @@ def test_apply_inventory_mapping_fallback_match_rule(app, client, tmp_path):
json={
"task_id": task_id,
"column_mapping_json": {
"sku": "AWS Sku",
"part_number": "Supplier Sku",
"reservation_id": "COM ID",
"available_qty": "Qty Available",
},
@@ -1182,7 +1218,7 @@ def test_apply_inventory_mapping_fallback_match_rule(app, client, tmp_path):
)
apply_data = apply_res.get_json()
match_rule = apply_data["data"]["field_alignment"]["match_rule"]
assert "AWS Sku" in match_rule
assert "Supplier Sku" in match_rule
assert "COM ID" in match_rule
assert apply_data["data"]["field_alignment"].get("match_rule_source") == "fallback"
@@ -1244,7 +1280,7 @@ def test_apply_inventory_mapping_custom_headers(app, client, tmp_path):
json={
"task_id": task_id,
"column_mapping_json": {
"sku": "Part No",
"part_number": "Part No",
"reservation_id": "Resv",
"available_qty": "On Hand",
},
@@ -1254,7 +1290,7 @@ def test_apply_inventory_mapping_custom_headers(app, client, tmp_path):
assert apply_data["status"] == "needs_human"
assert apply_data["data"]["field_alignment"]["inventory_row_count"] == 1
sample = apply_data["data"]["field_alignment"]["sample_inventory_lines"][0]
assert sample["sku"] == "SKU-99"
assert sample["part_number"] == "SKU-99"
assert sample["available_qty"] == 12
@@ -1276,7 +1312,7 @@ def test_confirm_parse_does_not_skip_inventory_match(app, client):
"structured": {
"customer_name": "Wistron",
"ship_to": "Dublin",
"lines": [{"sku": "504-010213-001", "reservation_id": "R-1", "qty": 9, "uom": "EA"}],
"lines": [{"part_number": "504-010213-001", "reservation_id": "R-1", "qty": 9, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -1333,7 +1369,7 @@ def test_parse_notice_blocks_when_reservation_id_missing(app, client, monkeypatc
"task_id": task_id,
"structured": {
"customer_name": "ACME",
"lines": [{"sku": "A001", "qty": 10, "uom": "EA"}],
"lines": [{"part_number": "A001", "qty": 10, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -1380,7 +1416,8 @@ def test_parse_notice_blocks_invalid_nonempty_reservation_id(app, client, monkey
"structured": {
"lines": [
{
"sku": "TEMP-S000218929/D4-A08AR12000002",
"part_number": "D4-A08AR12000002",
"customer_part_number": "TEMP-S000218929",
"reservation_id": "1f1a682dfdc446a393415dee93eb36ce",
"qty": 10,
"uom": "EA",
@@ -1421,7 +1458,7 @@ def test_human_edit_revalidates_reservation_and_blocks_stale_confirm(app, client
json={
"task_id": task_id,
"structured": {
"lines": [{"sku": "A001", "reservation_id": "1000140351", "qty": 2, "uom": "EA"}],
"lines": [{"part_number": "A001", "reservation_id": "1000140351", "qty": 2, "uom": "EA"}],
"confidence": 0.4,
},
},
@@ -1463,7 +1500,7 @@ def test_parse_notice_blocks_valid_reservation_when_column_evidence_conflicts(ap
headers=headers,
json={"source_type": "manual"},
).get_json()["task_id"]
raw_text = "AWS Sku\tReservation ID\tQty\nA001\t3000092917\t2"
raw_text = "Part Number\tReservation ID\tQty\nA001\t3000092917\t2"
result = client.post(
"/api/shipping-notice/tools/parse_notice",
@@ -1472,7 +1509,7 @@ def test_parse_notice_blocks_valid_reservation_when_column_evidence_conflicts(ap
"task_id": task_id,
"raw_text": raw_text,
"structured": {
"lines": [{"sku": "A001", "reservation_id": "3000092918", "qty": 2, "uom": "EA"}],
"lines": [{"part_number": "A001", "reservation_id": "3000092918", "qty": 2, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -1510,7 +1547,7 @@ def test_parse_notice_low_confidence_does_not_write_parse_review_chat_card(app,
"conversation_id": "conv-no-parse-card",
"structured": {
"customer_name": "ACME",
"lines": [{"sku": "A001", "reservation_id": "1000140351", "qty": 10, "uom": "EA"}],
"lines": [{"part_number": "A001", "reservation_id": "1000140351", "qty": 10, "uom": "EA"}],
"confidence": 0.4,
},
},
@@ -1553,7 +1590,7 @@ def test_parse_notice_auto_continue_hides_parse_confirmation_hint(app, client, m
"task_id": task_id,
"structured": {
"customer_name": "ACME",
"lines": [{"sku": "A001", "reservation_id": "R-1", "qty": 10, "uom": "EA"}],
"lines": [{"part_number": "A001", "reservation_id": "R-1", "qty": 10, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -1598,7 +1635,7 @@ def test_submit_decision_confirm_during_waiting_inventory_is_not_failed(app, cli
"task_id": task_id,
"structured": {
"customer_name": "ACME",
"lines": [{"sku": "A001", "reservation_id": "R-1", "qty": 10, "uom": "EA"}],
"lines": [{"part_number": "A001", "reservation_id": "R-1", "qty": 10, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -1646,7 +1683,7 @@ def test_submit_decision_confirm_inventory_mapping_enqueues_worker(app, client,
"task_id": task_id,
"structured": {
"customer_name": "ACME",
"lines": [{"sku": "A001", "reservation_id": "R-1", "qty": 10, "uom": "EA"}],
"lines": [{"part_number": "A001", "reservation_id": "R-1", "qty": 10, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -1656,7 +1693,7 @@ def test_submit_decision_confirm_inventory_mapping_enqueues_worker(app, client,
task = ShippingTask.query.filter_by(task_no=task_id).first()
assert task is not None
task_db_id = task.id
task.inventory_lines_json = [{"sku": "A001", "reservation_id": "R-1", "available_qty": 10}]
task.inventory_lines_json = [{"part_number": "A001", "reservation_id": "R-1", "available_qty": 10}]
task.process_status = "inventory_ready"
task.review_status = "align_review"
task.pending_human_reason = "align_review"
@@ -1672,7 +1709,7 @@ def test_submit_decision_confirm_inventory_mapping_enqueues_worker(app, client,
"headers": ["Reservation ID", "SKU", "Qty Available"],
"field_mapping": {
"reservation_id": "Reservation ID",
"sku": "SKU",
"part_number": "SKU",
"available_qty": "Qty Available",
},
"mapping": {
@@ -1720,13 +1757,14 @@ def test_retry_rpa_force_refresh_clears_inventory_mapping_state(app, client, tmp
with app.app_context():
task = ShippingTask.query.filter_by(task_no=task_id).first()
assert task is not None
task.lines_json = [{"part_number": "A001", "reservation_id": "R-1", "qty": 1}]
task.process_status = "inventory_ready"
task.review_status = "align_review"
task.pending_human_reason = "align_review"
task.inventory_lines_json = [{"sku": "OLD", "reservation_id": "R-1", "available_qty": 3}]
task.inventory_lines_json = [{"part_number": "OLD", "reservation_id": "R-1", "available_qty": 3}]
task.match_status = "fulfillable"
task.shortage_json = {"lines": []}
task.line_results_json = [{"sku": "OLD", "status": "ok"}]
task.line_results_json = [{"part_number": "OLD", "status": "ok"}]
task.export_file_path = str(tmp_path / "old.xlsx")
task.export_file_name = "old.xlsx"
task.upload_status = "failed"
@@ -1797,6 +1835,7 @@ def test_rpa_pending_timeout_recheck_marks_task_needs_human_after_single_attempt
with app.app_context():
task = ShippingTask.query.filter_by(task_no=task_id).first()
assert task is not None
task.lines_json = [{"part_number": "A001", "reservation_id": "R-1", "qty": 1}]
task.process_status = "waiting_inventory"
task.pending_human_reason = PH_RPA_PENDING
task.step_payload_json = {
@@ -1860,6 +1899,7 @@ def test_retry_rpa_after_exhausted_starts_new_attempt_window(app, client, tmp_pa
with app.app_context():
task = ShippingTask.query.filter_by(task_no=task_id).first()
assert task is not None
task.lines_json = [{"part_number": "A001", "reservation_id": "R-1", "qty": 1}]
task.process_status = "waiting_inventory"
task.pending_human_reason = PH_RPA_EXHAUSTED
task.step_payload_json = {
@@ -1939,6 +1979,7 @@ def test_batch_retry_marks_timed_out_rpa_pending_task_as_exhausted(app, client,
with app.app_context():
task = ShippingTask.query.filter_by(task_no=task_id).first()
assert task is not None
task.lines_json = [{"part_number": "A001", "reservation_id": "R-1", "qty": 1}]
task.process_status = "waiting_inventory"
task.pending_human_reason = PH_RPA_PENDING
task.step_payload_json = {
@@ -1993,7 +2034,7 @@ def test_submit_decision_by_conversation_id(app, client):
"conversation_id": "conv-test-001",
"structured": {
"customer_name": "Wistron",
"lines": [{"sku": "504-010213-001", "reservation_id": "1000140351", "qty": 9, "uom": "EA"}],
"lines": [{"part_number": "504-010213-001", "reservation_id": "1000140351", "qty": 9, "uom": "EA"}],
"confidence": 0.95,
},
},
@@ -2028,7 +2069,7 @@ def test_submit_decision_requires_task_id_when_conversation_has_multiple_tasks(a
review_status="parse_review",
pending_human_reason="low_confidence",
source_type="manual",
lines_json=[{"sku": "A001", "reservation_id": "1000140351", "qty": 1}],
lines_json=[{"part_number": "A001", "reservation_id": "1000140351", "qty": 1}],
)
second = ShippingTask(
task_no="SN-MULTI-CONV-002",
@@ -2037,7 +2078,7 @@ def test_submit_decision_requires_task_id_when_conversation_has_multiple_tasks(a
review_status="parse_review",
pending_human_reason="low_confidence",
source_type="manual",
lines_json=[{"sku": "A002", "reservation_id": "1000140352", "qty": 1}],
lines_json=[{"part_number": "A002", "reservation_id": "1000140352", "qty": 1}],
)
with app.app_context():
db.session.add_all([first, second])
@@ -2147,4 +2188,3 @@ def test_chat_actions_empty_when_task_rejected(app):
ui_state = build_task_ui_state(task)
assert ui_state["checkpoint"] == "rejected"
assert ui_state["action_buttons"] == []