refactor: gate LF candidates with current AR836 response
This commit is contained in:
1 parent
f1099c84dd
commit
127d88e84e
6 files changed
+112
-244
No files matched your search
@@ -40,11 +40,6 @@ def successful_payload() -> dict[str, object]:
|
||||
},
|
||||
"库存信息": {
|
||||
"可用库存(扣除了待产数量)": 100,
|
||||
"现货数": 100,
|
||||
"需排产数": 0,
|
||||
"对应来福减速器编码": "20.30.00999",
|
||||
"减速器实际可用量": 100,
|
||||
"逾期待复核销售订单": [],
|
||||
},
|
||||
"BOM信息": {"是否有BOM(False则需提醒无BOM)": True},
|
||||
"采购信息": {"缺料明细": []},
|
||||
@@ -55,11 +50,6 @@ def successful_payload() -> dict[str, object]:
|
||||
def set_stock(payload: dict[str, object], stock: object, demand: int) -> None:
|
||||
inventory = payload["data"]["库存信息"]
|
||||
inventory["可用库存(扣除了待产数量)"] = stock
|
||||
inventory["现货数"] = stock
|
||||
if isinstance(stock, (int, float)) and not isinstance(stock, bool):
|
||||
inventory["需排产数"] = max(demand - stock, 0)
|
||||
else:
|
||||
inventory["需排产数"] = None
|
||||
|
||||
|
||||
def message_event(message_id: str, chat_id: str, open_id: str) -> SimpleNamespace:
|
||||
@@ -463,7 +453,7 @@ class OriginalDemandQueryTests(unittest.TestCase):
|
||||
for call in run.call_args_list:
|
||||
command = call.args[0]
|
||||
self.assertEqual(command[command.index('--quantity') + 1], '12')
|
||||
self.assertIn('现货数10台;需排产数2台', report)
|
||||
self.assertIn('整机可用库存10台(部分覆盖,仍需补齐2台)', report)
|
||||
self.assertIn('8个工作日,最终交货日期:2026-10-27', report)
|
||||
self.assertNotIn('误走现货分支', report)
|
||||
self.assertNotIn('排产测算数量', report)
|
||||
@@ -546,55 +536,68 @@ class OriginalDemandQueryTests(unittest.TestCase):
|
||||
class LfStockGateTests(unittest.TestCase):
|
||||
LF_MODEL = "eRob70F50I-FHM-18ET(V4)"
|
||||
|
||||
def details(self, demand: int, stock: int, reducer_stock: int | None) -> dict[str, object]:
|
||||
def details(
|
||||
self,
|
||||
demand: int,
|
||||
stock: int,
|
||||
shortages: list[dict[str, object]] | None,
|
||||
) -> dict[str, object]:
|
||||
payload = successful_payload()
|
||||
set_stock(payload, stock, demand)
|
||||
inventory = payload["data"]["库存信息"]
|
||||
inventory["对应来福减速器编码"] = "20.30.00999"
|
||||
inventory["减速器实际可用量"] = reducer_stock
|
||||
if shortages is None:
|
||||
del payload["data"]["采购信息"]["缺料明细"]
|
||||
else:
|
||||
payload["data"]["采购信息"]["缺料明细"] = shortages
|
||||
return bridge.lead_time_details(payload, demand)
|
||||
|
||||
def test_full_finished_goods_stock_passes_without_reducer_stock(self) -> None:
|
||||
details = self.details(demand=10, stock=10, reducer_stock=None)
|
||||
|
||||
self.assertEqual(details["stock_on_hand"], 10)
|
||||
self.assertEqual(details["production_required"], 0)
|
||||
self.assertIsNone(bridge.lf_stock_gate_reason(self.LF_MODEL, details))
|
||||
|
||||
def test_partial_finished_goods_and_reducer_stock_must_cover_all_demand(self) -> None:
|
||||
covered = self.details(demand=10, stock=3, reducer_stock=7)
|
||||
insufficient = self.details(demand=10, stock=3, reducer_stock=6)
|
||||
|
||||
self.assertIsNone(bridge.lf_stock_gate_reason(self.LF_MODEL, covered))
|
||||
self.assertIn(
|
||||
"合计不足",
|
||||
bridge.lf_stock_gate_reason(self.LF_MODEL, insufficient),
|
||||
def test_full_finished_goods_stock_passes_even_with_reducer_shortage(self) -> None:
|
||||
details = self.details(
|
||||
demand=10,
|
||||
stock=10,
|
||||
shortages=[{"缺料物料": "20.30.00999"}],
|
||||
)
|
||||
|
||||
def test_zero_finished_goods_and_zero_reducer_stock_is_excluded(self) -> None:
|
||||
details = self.details(demand=10, stock=0, reducer_stock=0)
|
||||
self.assertEqual(details["available_inventory"], 10)
|
||||
self.assertIsNone(bridge.lf_stock_gate_reason(self.LF_MODEL, details))
|
||||
|
||||
self.assertIsNotNone(bridge.lf_stock_gate_reason(self.LF_MODEL, details))
|
||||
def test_partial_stock_passes_when_ar836_returns_no_reducer_constraint(self) -> None:
|
||||
details = self.details(demand=10, stock=3, shortages=[])
|
||||
|
||||
def test_inconsistent_production_required_is_excluded(self) -> None:
|
||||
payload = successful_payload()
|
||||
set_stock(payload, 3, 10)
|
||||
payload["data"]["库存信息"]["需排产数"] = 6
|
||||
details = bridge.lead_time_details(payload, 10)
|
||||
self.assertIsNone(bridge.lf_stock_gate_reason(self.LF_MODEL, details))
|
||||
|
||||
def test_partial_stock_and_reducer_shortage_is_excluded(self) -> None:
|
||||
details = self.details(
|
||||
demand=10,
|
||||
stock=3,
|
||||
shortages=[{"缺料物料": "20.30.00999"}],
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
"不一致",
|
||||
"AR836返回减速器供应约束",
|
||||
bridge.lf_stock_gate_reason(self.LF_MODEL, details),
|
||||
)
|
||||
|
||||
def test_missing_compact_stock_fields_is_excluded(self) -> None:
|
||||
def test_zero_stock_passes_when_ar836_returns_no_reducer_constraint(self) -> None:
|
||||
details = self.details(demand=10, stock=0, shortages=[])
|
||||
|
||||
self.assertIsNone(bridge.lf_stock_gate_reason(self.LF_MODEL, details))
|
||||
|
||||
def test_missing_shortage_details_is_excluded_when_stock_is_partial(self) -> None:
|
||||
details = self.details(demand=10, stock=3, shortages=None)
|
||||
|
||||
self.assertIn(
|
||||
"未返回可核验的缺料明细",
|
||||
bridge.lf_stock_gate_reason(self.LF_MODEL, details),
|
||||
)
|
||||
|
||||
def test_explicit_missing_bom_is_excluded_when_stock_is_partial(self) -> None:
|
||||
payload = successful_payload()
|
||||
del payload["data"]["库存信息"]["现货数"]
|
||||
del payload["data"]["库存信息"]["需排产数"]
|
||||
set_stock(payload, 3, 10)
|
||||
payload["data"]["BOM信息"]["是否有BOM(False则需提醒无BOM)"] = False
|
||||
details = bridge.lead_time_details(payload, 10)
|
||||
|
||||
self.assertIn(
|
||||
"未返回可核验",
|
||||
"未返回可核验的缺料明细",
|
||||
bridge.lf_stock_gate_reason(self.LF_MODEL, details),
|
||||
)
|
||||
|
||||
@@ -610,7 +613,9 @@ class LfStockGateTests(unittest.TestCase):
|
||||
payload = successful_payload()
|
||||
if query_request.model == lf_model:
|
||||
set_stock(payload, 3, query_request.quantity)
|
||||
payload["data"]["库存信息"]["减速器实际可用量"] = 6
|
||||
payload["data"]["采购信息"]["缺料明细"] = [
|
||||
{"缺料物料": "20.30.00999", "物料名称": "来福减速器"}
|
||||
]
|
||||
return payload
|
||||
|
||||
with (
|
||||
@@ -629,19 +634,8 @@ class LfStockGateTests(unittest.TestCase):
|
||||
[item["model"] for item in record.call_args.args[2]],
|
||||
)
|
||||
|
||||
def test_covered_lf_candidate_shows_stock_basis_and_overdue_order(self) -> None:
|
||||
payload = successful_payload()
|
||||
set_stock(payload, 3, 10)
|
||||
inventory = payload["data"]["库存信息"]
|
||||
inventory["减速器实际可用量"] = 7
|
||||
inventory["逾期待复核销售订单"] = [
|
||||
{
|
||||
"销售订单编码": "SAL-OVERDUE-001",
|
||||
"要货日期": "2026-09-01",
|
||||
"逾期天数": 35,
|
||||
}
|
||||
]
|
||||
details = bridge.lead_time_details(payload, 10)
|
||||
def test_eligible_lf_candidate_uses_current_inventory_wording(self) -> None:
|
||||
details = self.details(demand=10, stock=3, shortages=[])
|
||||
candidate = {
|
||||
"index": 2,
|
||||
"model": self.LF_MODEL,
|
||||
@@ -654,10 +648,8 @@ class LfStockGateTests(unittest.TestCase):
|
||||
|
||||
report = "\n".join(bridge.candidate_report_lines(candidate, 10))
|
||||
|
||||
self.assertIn("现货数3台;需排产数7台", report)
|
||||
self.assertIn("实际可用量7件", report)
|
||||
self.assertIn("SAL-OVERDUE-001", report)
|
||||
self.assertIn("是否释放现货", report)
|
||||
self.assertIn("整机可用库存3台(部分覆盖,仍需补齐7台)", report)
|
||||
self.assertNotIn("减速器实际可用量", report)
|
||||
|
||||
|
||||
class CandidateBatchTests(unittest.TestCase):
|
||||
|
||||