feat(box): simplify boxing mode API
This commit is contained in:
@@ -84,8 +84,8 @@ def test_box_save_zongpai_not_found(client: TestClient):
|
||||
assert resp.json()["error_code"] == "ZONGPAI_NOT_FOUND"
|
||||
|
||||
|
||||
def test_box_save_many_to_one_appends_different_zongpais(client: TestClient):
|
||||
"""多码一箱:同一排产号同一箱号可追加不同总排号。"""
|
||||
def test_box_save_multi_code_appends_different_zongpais(client: TestClient):
|
||||
"""多码凑箱:同一排产号同一箱号可追加不同总排号。"""
|
||||
box_no = 901
|
||||
first = client.post(
|
||||
"/CargoTrace/box",
|
||||
@@ -93,7 +93,6 @@ def test_box_save_many_to_one_appends_different_zongpais(client: TestClient):
|
||||
"zongpai_no": "26BW0011",
|
||||
"box_no": box_no,
|
||||
"quantity": 10,
|
||||
"box_mode": "many-to-one",
|
||||
},
|
||||
)
|
||||
assert first.status_code == 200
|
||||
@@ -105,7 +104,6 @@ def test_box_save_many_to_one_appends_different_zongpais(client: TestClient):
|
||||
"zongpai_no": "26BW0012",
|
||||
"box_no": box_no,
|
||||
"quantity": 8,
|
||||
"box_mode": "many-to-one",
|
||||
},
|
||||
)
|
||||
assert second.status_code == 200
|
||||
@@ -126,8 +124,8 @@ def test_box_save_many_to_one_appends_different_zongpais(client: TestClient):
|
||||
assert isinstance(item["total_quantity"], int)
|
||||
|
||||
|
||||
def test_box_save_many_to_one_duplicate_same_zongpai(client: TestClient):
|
||||
"""多码一箱:同箱同总排重复录入返回 DUPLICATE_BOX_NO。"""
|
||||
def test_box_save_multi_code_duplicate_same_zongpai(client: TestClient):
|
||||
"""多码凑箱:同箱同总排重复录入返回 DUPLICATE_BOX_NO。"""
|
||||
box_no = 902
|
||||
first = client.post(
|
||||
"/CargoTrace/box",
|
||||
@@ -135,7 +133,6 @@ def test_box_save_many_to_one_duplicate_same_zongpai(client: TestClient):
|
||||
"zongpai_no": "26BW0011",
|
||||
"box_no": box_no,
|
||||
"quantity": 10,
|
||||
"box_mode": "many-to-one",
|
||||
},
|
||||
)
|
||||
assert first.status_code == 200
|
||||
@@ -146,13 +143,52 @@ def test_box_save_many_to_one_duplicate_same_zongpai(client: TestClient):
|
||||
"zongpai_no": "26BW0011",
|
||||
"box_no": box_no,
|
||||
"quantity": 5,
|
||||
"box_mode": "many-to-one",
|
||||
},
|
||||
)
|
||||
assert duplicate.status_code == 409
|
||||
assert duplicate.json()["error_code"] == "DUPLICATE_BOX_NO"
|
||||
|
||||
|
||||
def test_box_save_split_same_zongpai_up_to_total_quantity(client: TestClient):
|
||||
"""单码装箱:同一总排号可分箱提交,累计等于 ERP 数量时成功。"""
|
||||
first = client.post(
|
||||
"/CargoTrace/box",
|
||||
json={"zongpai_no": "26BW0011", "box_no": 905, "quantity": 30},
|
||||
)
|
||||
assert first.status_code == 200
|
||||
|
||||
second = client.post(
|
||||
"/CargoTrace/box",
|
||||
json={"zongpai_no": "26BW0011", "box_no": 906, "quantity": 50},
|
||||
)
|
||||
assert second.status_code == 200
|
||||
|
||||
info = client.get("/CargoTrace/box/info", params={"zongpai_no": "26BW0011"})
|
||||
assert info.status_code == 200
|
||||
current_boxes = [
|
||||
item
|
||||
for item in info.json()["current_zongpai_boxes"]
|
||||
if item["box_no"] in (905, 906)
|
||||
]
|
||||
assert sum(item["quantity"] for item in current_boxes) == 80
|
||||
|
||||
|
||||
def test_box_save_rejects_quantity_over_remaining(client: TestClient):
|
||||
"""保存后累计数量超过 ERP 总数量时返回 INVALID_QUANTITY。"""
|
||||
created = client.post(
|
||||
"/CargoTrace/box",
|
||||
json={"zongpai_no": "26BW0011", "box_no": 907, "quantity": 70},
|
||||
)
|
||||
assert created.status_code == 200
|
||||
|
||||
over = client.post(
|
||||
"/CargoTrace/box",
|
||||
json={"zongpai_no": "26BW0011", "box_no": 908, "quantity": 11},
|
||||
)
|
||||
assert over.status_code == 400
|
||||
assert over.json()["error_code"] == "INVALID_QUANTITY"
|
||||
|
||||
|
||||
def test_box_update_same_box_no_does_not_conflict(client: TestClient):
|
||||
"""PATCH 原箱号未变时,应排除当前 box_item_id,避免误判重复。"""
|
||||
box_no = 903
|
||||
@@ -162,7 +198,6 @@ def test_box_update_same_box_no_does_not_conflict(client: TestClient):
|
||||
"zongpai_no": "26BW0011",
|
||||
"box_no": box_no,
|
||||
"quantity": 10,
|
||||
"box_mode": "one-to-many",
|
||||
},
|
||||
)
|
||||
assert created.status_code == 200
|
||||
@@ -170,12 +205,35 @@ def test_box_update_same_box_no_does_not_conflict(client: TestClient):
|
||||
|
||||
updated = client.patch(
|
||||
f"/CargoTrace/box/{box_item_id}",
|
||||
json={"box_no": box_no, "quantity": 7, "box_mode": "one-to-many"},
|
||||
json={"box_no": box_no, "quantity": 7},
|
||||
)
|
||||
assert updated.status_code == 200
|
||||
assert updated.json()["quantity"] == 7
|
||||
|
||||
|
||||
def test_box_update_rejects_quantity_over_remaining(client: TestClient):
|
||||
"""PATCH 调整数量导致累计超过 ERP 总数量时返回 INVALID_QUANTITY。"""
|
||||
first = client.post(
|
||||
"/CargoTrace/box",
|
||||
json={"zongpai_no": "26BW0011", "box_no": 909, "quantity": 70},
|
||||
)
|
||||
assert first.status_code == 200
|
||||
|
||||
second = client.post(
|
||||
"/CargoTrace/box",
|
||||
json={"zongpai_no": "26BW0011", "box_no": 910, "quantity": 5},
|
||||
)
|
||||
assert second.status_code == 200
|
||||
box_item_id = second.json()["box_item_id"]
|
||||
|
||||
over = client.patch(
|
||||
f"/CargoTrace/box/{box_item_id}",
|
||||
json={"box_no": 910, "quantity": 11},
|
||||
)
|
||||
assert over.status_code == 400
|
||||
assert over.json()["error_code"] == "INVALID_QUANTITY"
|
||||
|
||||
|
||||
def test_box_delete_removes_empty_box(client: TestClient):
|
||||
"""DELETE 删除最后一条明细后,同步清理空箱号。"""
|
||||
box_no = 904
|
||||
@@ -185,7 +243,6 @@ def test_box_delete_removes_empty_box(client: TestClient):
|
||||
"zongpai_no": "26BW0011",
|
||||
"box_no": box_no,
|
||||
"quantity": 10,
|
||||
"box_mode": "many-to-one",
|
||||
},
|
||||
)
|
||||
assert created.status_code == 200
|
||||
@@ -201,7 +258,6 @@ def test_box_delete_removes_empty_box(client: TestClient):
|
||||
"zongpai_no": "26BW0012",
|
||||
"box_no": box_no,
|
||||
"quantity": 8,
|
||||
"box_mode": "one-to-many",
|
||||
},
|
||||
)
|
||||
assert recreated.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user