diff --git a/capabilities/am516-delivery-prediction/docs/acceptance_samples.md b/capabilities/am516-delivery-prediction/docs/acceptance_samples.md index d53218f..b267ed7 100644 --- a/capabilities/am516-delivery-prediction/docs/acceptance_samples.md +++ b/capabilities/am516-delivery-prediction/docs/acceptance_samples.md @@ -48,9 +48,8 @@ Expected: - each future appended candidate row records the same query-completion time in `YYYY-MM-DD HH:mm:ss +0800` form (with the actual local UTC offset), without rewriting or backfilling historical records; - record-table columns follow this order: 序号、记录时间、型号、推荐类型、差异项、API状态、AM516预测交期、可用库存、主导因素; - unavailable candidates remain in their original rule order and are recorded as `❌ 不可用` with unavailable result fields shown as `—`; lack of a result does not itself establish that the model does not exist; -- generated LF candidates pass only when `现货数` and matching LF reducer actual availability cover the original demand; an LF candidate with insufficient combined coverage, missing stock fields, no matched reducer or an inconsistent `需排产数` is absent from the report, fastest comparison, candidate counts and `不可用候选`; -- retained results display `现货数` and `需排产数`; retained LF candidates needing production also display the matched reducer code and reducer actual available quantity; -- overdue unreserved sales orders returned by the API display the sales-order code and a human-review reminder without automatically releasing inventory; +- generated LF candidates pass when finished-product available inventory covers demand, or when the readable AR836 shortage list contains no `20.30.*` reducer constraint after AR836's 95% yield, five-unit rounding and BOM calculation; +- an LF candidate with insufficient finished-product inventory plus a `20.30.*` shortage, or with an unreadable shortage list, is absent from the report, fastest comparison, candidate counts and `不可用候选`; ## Sample 1B | API Workdays And Final Delivery Date diff --git a/capabilities/am516-delivery-prediction/docs/lf_reducer_stock_gate.md b/capabilities/am516-delivery-prediction/docs/lf_reducer_stock_gate.md index 146058c..6b728e6 100644 --- a/capabilities/am516-delivery-prediction/docs/lf_reducer_stock_gate.md +++ b/capabilities/am516-delivery-prediction/docs/lf_reducer_stock_gate.md @@ -1,59 +1,36 @@ -# 来福减速器存量清仓候选门禁 +# 来福减速器存量清仓候选门禁(AR836 当前接口版) ## 背景 -来福减速器后续不再采购。使用来福减速器的候选整机只能依据当前整机现货和对应来福减速器实际可用库存推荐,不能用采购在途、待检、固定提前期或未来补货能力补足数量。 +来福减速器后续不再采购。使用来福减速器的生成候选,必须有整机可用库存或 AR836 根据本次排产需求核算后确认减速器不构成供应约束,不能只凭型号相似和预测交期推荐。 -## AR836 接口字段 +## 当前使用的 AR836 字段 -AM516 从 `data.库存信息` 读取以下精简字段: +AM516 仅依赖现有接口已返回的: -- `现货数`:候选整机实际可用量。它不是 ERP 库存量,也不是未补扣销售订单占用的可用量。 -- `需排产数`:`max(需求数量 - 现货数, 0)`。 -- `对应来福减速器编码`:候选型号匹配的来福减速器物料编码。 -- `减速器实际可用量`:ERP 即时库存口径下可用于本次生产的数量。 -- `逾期待复核销售订单`:可选列表;订单超过要货日期 30 天但仍有待锁库/待预留数量时,包含销售订单编码、要货日期和逾期天数。 +- `data.库存信息.可用库存(扣除了待产数量)`:候选整机的当前可用库存口径。 +- `data.采购信息.缺料明细[]` 及其 `缺料物料`:物料编码以 `20.30.` 开头的记录视为减速器供应约束。 -`现货数`由 AR836/ERP 侧计算: +AR836 已在内部按下列口径把订单数量换算为排产和 BOM 需求: ```text -整机实际可用量 -= max( - ERP可用量(主单位) - - 有效销售订单待锁库/待预留数量(换算为主单位), 0 - ) +成品缺口 = max(订单需求 - 净可用成品库存, 0) +本次排产量 = ceil(成品缺口 / 95% / 5) × 5 ``` -AM516 不要求接口返回、也不在报告展示以下中间字段: - -- `ERP可用量(主单位)` -- `待锁库待预留数量(主单位)` -- `实际可用量` -- `每台减速器用量` -- `合计可覆盖整机数量` -- `本次需求数量` -- `是否满足推荐门槛` +AR836 根据该排产量、BOM 用量、存量需求和当前供应判定减速器是否进入缺料明细。AM516 不重复实现 95% 合格率和 5 台取整。 ## 推荐门禁 -当前业务按每台关节模组使用一件对应减速器判断: - ```text -现货数 = 整机实际可用量 -需排产数 = max(需求数量 - 现货数, 0) - -需排产数 = 0 - -> 整机现货已覆盖,可保留 LF 候选 - -需排产数 > 0 且 减速器实际可用量 >= 需排产数 - -> 整机现货与减速器库存合计覆盖,可保留 LF 候选 - -其他情况 - -> 剔除 LF 候选 +若 整机可用库存 >= 本次需求数量 -> 保留 +否则,若 缺料明细缺失或不可读 -> 保守剔除 +否则,若 缺料明细中存在 20.30.* 物料 -> 剔除 +否则 -> AR836 未发现减速器供应约束,保留 ``` -以下情况同样剔除:字段缺失或不可读、`需排产数`与公式不一致、需要排产但无对应减速器编码。 - 被剔除的 LF 型号不出现在关节模组交期预估报告、不可用候选、最快交期比较、现货候选或候选统计中。原始输入型号仍作为基准展示,不按“生成候选”处理。 -逾期销售订单只触发人工复核提醒,不自动释放库存;在 ERP 完成释放前,其待锁库/待预留数量仍由 AR836 扣除在`现货数`之外。 +## 当前接口的边界 + +减速器未进入缺料明细时,当前接口不返回匹配减速器编码和确切库存。本版也不具备销售订单待锁库/待预留的二次扣减、逾期 30 天订单提醒能力;这些需要 AR836 后续增加数据后才能严格实现。 diff --git a/capabilities/am516-delivery-prediction/rules/eRob关节模组相似型号推荐规则_v3.1.md b/capabilities/am516-delivery-prediction/rules/eRob关节模组相似型号推荐规则_v3.1.md index daf1fcc..91d7938 100644 --- a/capabilities/am516-delivery-prediction/rules/eRob关节模组相似型号推荐规则_v3.1.md +++ b/capabilities/am516-delivery-prediction/rules/eRob关节模组相似型号推荐规则_v3.1.md @@ -222,16 +222,16 @@ AI 输出中不得使用“已替代”“已承诺”“可直接交付”等 来福减速器后续不再采购,因此 `(Vx)` 来福候选不能只凭型号配置相似和预测交期进入报告。 -对每个来福候选读取 AR836 返回的: +对每个来福候选读取 AR836 当前返回的: ```text -现货数 = 候选整机实际可用量 -需排产数 = max(本次需求数量 - 现货数, 0) +data.库存信息.可用库存(扣除了待产数量) +data.采购信息.缺料明细[].缺料物料 ``` -- `需排产数 = 0`:整机现货覆盖本次需求,可保留候选。 -- `需排产数 > 0`:对应来福减速器实际可用量必须大于等于需排产数,才可保留候选。 -- 整机现货与减速器库存合计不足,或库存字段缺失、无匹配减速器、数量口径矛盾:剔除候选。 +- 整机可用库存覆盖需求:保留候选。 +- 整机库存不足,且缺料明细中出现 `20.30.*` 减速器物料:剔除候选。 +- 整机库存不足,但 AR836 按 95% 合格率、5 台取整及 BOM 用量核算后未返回减速器供应约束:保留候选。 +- 缺料明细缺失或不可读:保守剔除。 - 被剔除型号不进入交期报告、最快交期比较或不可用候选清单。 -- 采购在途、待检、固定提前期和未来采购不得作为放行依据。 -- 超过要货日期30天且仍有待锁库/待预留数量的销售订单只提示人工复核,不自动释放现货。 +- 当前接口无法在减速器不缺料时单独展示匹配编码和确切库存,也无法实现销售订单待锁库/待预留二次扣减及逾期 30 天提醒。 diff --git a/capabilities/am516-delivery-prediction/skills/joint-module-leadtime-report/SKILL.md b/capabilities/am516-delivery-prediction/skills/joint-module-leadtime-report/SKILL.md index 92d278d..523e2b5 100644 --- a/capabilities/am516-delivery-prediction/skills/joint-module-leadtime-report/SKILL.md +++ b/capabilities/am516-delivery-prediction/skills/joint-module-leadtime-report/SKILL.md @@ -133,14 +133,12 @@ Do not use temporary curl, WebFetch, or any API method outside the controlled sc ## LF Reducer Stock Gate - Apply this gate only to generated LF candidates, identified by `(Vx)`. -- Read `现货数`、`需排产数`、`对应来福减速器编码`、`减速器实际可用量` from `data.库存信息`. -- `现货数` means the finished product's actual available quantity after AR836 has deducted valid sales-order quantities waiting for locking/reservation. -- Require `需排产数 = max(原始需求数量 - 现货数, 0)`. -- If `需排产数 = 0`, the finished-product stock covers demand and the candidate passes without reducer replenishment. -- Otherwise require a matched LF reducer code and `减速器实际可用量 >= 需排产数`. -- Missing, invalid, inconsistent or insufficient fields reject the LF candidate. Purchasing in transit, inspection stock, fixed lead time and future replenishment must not rescue it. -- Show `现货数` and `需排产数` for retained results. Show the matched LF reducer code and actual available quantity for retained LF candidates that need production. -- If `逾期待复核销售订单` is returned, show its sales-order code and request human review. Never release stock automatically. +- Read `data.库存信息.可用库存(扣除了待产数量)` and `data.采购信息.缺料明细` from the current AR836 response. +- AR836 owns the 95% yield, five-unit rounding and BOM-demand calculation. AM516 must not reproduce a different quantity formula. +- If finished-product available inventory covers the original demand, retain the candidate. +- Otherwise reject when the shortage list is missing/unreadable or contains any material code beginning `20.30.`; retain when the readable list contains no such reducer constraint. +- Rejected LF candidates are omitted from the report, fastest comparison, candidate counts and `不可用候选`. +- Do not claim that the current response proves the matched reducer code or exact reducer stock when no reducer shortage record is returned. - The original input model remains the baseline; this generated-candidate gate does not hide the user's original model. ## Unavailable Result Reasons @@ -211,7 +209,7 @@ Use this field order for a successful Feishu report: 1. {model}({candidate type and reducer brand}) - 需求数量:{input quantity}台 - AM516预测交期:{API workdays}个工作日,最终交货日期:{API final delivery date} -- 现货/排产情况:现货数{actual available finished goods}台;需排产数{remaining production quantity}台 +- 可用库存/覆盖情况:整机可用库存{AR836 available inventory}台({coverage statement}) - 主导因素:{main factor} - 推荐理由:{rule-based recommendation reason} - 差异项:{field changes formatted as `字段 原值→新值`; join multiple changes with `;`, for example `编码器 HS→HM;品牌 DZ→LF`} diff --git a/shared/runtime/feishu_bot_bridge.py b/shared/runtime/feishu_bot_bridge.py index 5a354ae..8d25ec2 100644 --- a/shared/runtime/feishu_bot_bridge.py +++ b/shared/runtime/feishu_bot_bridge.py @@ -4,7 +4,6 @@ import concurrent.futures import itertools import json import logging -import math import os import re import subprocess @@ -181,48 +180,27 @@ class CandidateUnavailableError(RuntimeError): pass -def nonnegative_quantity(value: Any) -> int | float | None: - """Return a finite nonnegative ERP quantity, excluding booleans.""" - if isinstance(value, bool) or not isinstance(value, (int, float)): - return None - if not math.isfinite(value) or value < 0: - return None - if isinstance(value, float) and not value.is_integer(): - return None - return value - - -def quantity_text(value: int | float) -> str: - return f"{value:g}" - - def is_lf_model(model: str) -> bool: match = MODEL_PATTERN.fullmatch(model) return bool(match and match.group("bracket") == "(") def lf_stock_gate_reason(model: str, details: dict[str, Any]) -> str | None: - """Return an internal exclusion reason for an LF candidate, or None when eligible.""" + """Use the current AR836 response to gate generated LF candidates.""" if not is_lf_model(model): return None - stock_on_hand = details.get("stock_on_hand") - production_required = details.get("production_required") - if stock_on_hand is None or production_required is None: - return "接口未返回可核验的现货数和需排产数" - if details.get("stock_quantity_consistent") is not True: - return "接口返回的需排产数与需求数量、现货数不一致" - if production_required == 0: + available_inventory = details.get("available_inventory") + requested_quantity = details.get("requested_quantity") + if available_inventory is None or requested_quantity is None: + return "接口未返回可核验的整机可用库存" + if available_inventory >= requested_quantity: return None - reducer_code = details.get("lf_reducer_code") - reducer_available = details.get("lf_reducer_available") - if not isinstance(reducer_code, str) or not reducer_code.strip(): - return "接口未返回与候选型号匹配的来福减速器编码" - if reducer_available is None: - return "接口未返回对应来福减速器实际可用量" - if reducer_available < production_required: - return "整机现货与对应来福减速器实际可用量合计不足" + if details.get("shortage_data_available") is not True: + return "接口未返回可核验的缺料明细" + if details.get("reducer_shortages"): + return "整机库存未覆盖需求且AR836返回减速器供应约束" return None @@ -707,42 +685,6 @@ def shortage_material_names_line(shortages: list[Any]) -> str: return f"- 缺料物料明细:{text}" -def stock_contract_value(data: dict[str, Any], field: str) -> Any: - """Read the compact stock contract, preferring data.库存信息.""" - inventory_info = data.get("库存信息") - if isinstance(inventory_info, dict) and field in inventory_info: - return inventory_info[field] - # Temporary compatibility for AR836 rollout samples that place the same - # compact fields directly under data. - return data.get(field) - - -def overdue_sales_order_lines(data: dict[str, Any]) -> list[str]: - orders = stock_contract_value(data, "逾期待复核销售订单") - if not isinstance(orders, list): - return [] - lines: list[str] = [] - for order in orders: - if not isinstance(order, dict): - continue - order_code = order.get("销售订单编码") - if not isinstance(order_code, str) or not order_code.strip(): - continue - parts = [f"销售订单编码{order_code.strip()}"] - required_date = order.get("要货日期") - if isinstance(required_date, str) and required_date.strip(): - parts.append(f"要货日期{required_date.strip()}") - overdue_days = whole_day_count(order.get("逾期天数")) - if overdue_days is not None: - parts.append(f"逾期{overdue_days}天") - lines.append( - "- 库存复核提醒:" - + ";".join(parts) - + ";请人工确认是否为客户逾期未提货订单及是否释放现货。" - ) - return lines - - def lead_time_details( payload: dict[str, Any], requested_quantity: int, @@ -802,33 +744,11 @@ def lead_time_details( prediction_value = None inventory_info = data.get("库存信息") - stock_on_hand = nonnegative_quantity(stock_contract_value(data, "现货数")) - production_required = nonnegative_quantity(stock_contract_value(data, "需排产数")) - expected_production_required = ( - max(requested_quantity - stock_on_hand, 0) - if stock_on_hand is not None - else None - ) - stock_quantity_consistent = ( - production_required is not None - and expected_production_required is not None - and math.isclose(production_required, expected_production_required, abs_tol=1e-9) - ) - lf_reducer_code = stock_contract_value(data, "对应来福减速器编码") - if not isinstance(lf_reducer_code, str) or not lf_reducer_code.strip(): - lf_reducer_code = None - else: - lf_reducer_code = lf_reducer_code.strip() - lf_reducer_available = nonnegative_quantity( - stock_contract_value(data, "减速器实际可用量") - ) - - legacy_available_inventory = ( + available_inventory = ( inventory_info.get("可用库存(扣除了待产数量)") if isinstance(inventory_info, dict) else None ) - available_inventory = stock_on_hand if stock_on_hand is not None else legacy_available_inventory # Inventory is display-only; invalid values do not invalidate API dates. if ( isinstance(available_inventory, bool) @@ -836,13 +756,7 @@ def lead_time_details( or (isinstance(available_inventory, float) and not available_inventory.is_integer()) ): available_inventory = None - if stock_on_hand is not None and production_required is not None: - inventory_text = ( - f"现货数{quantity_text(stock_on_hand)}台;" - f"需排产数{quantity_text(production_required)}台" - ) - full_coverage = production_required == 0 - elif available_inventory is not None: + if available_inventory is not None: if available_inventory >= requested_quantity: inventory_text = f"整机可用库存{available_inventory:g}台(完全覆盖)" full_coverage: bool | None = True @@ -865,16 +779,21 @@ def lead_time_details( ) purchase_info = data.get("采购信息") shortages = purchase_info.get("缺料明细") if isinstance(purchase_info, dict) else None - if has_bom is False: - evidence_lines = ["- 缺料/BOM摘要:API未返回有效BOM,需补充数据源。"] - elif isinstance(shortages, list) and shortages: - reducer_shortages = [ + shortage_data_available = has_bom is not False and isinstance(shortages, list) + reducer_shortages = ( + [ item for item in shortages if isinstance(item, dict) and isinstance(item.get("缺料物料"), str) and item["缺料物料"].startswith("20.30.") ] + if isinstance(shortages, list) + else [] + ) + if has_bom is False: + evidence_lines = ["- 缺料/BOM摘要:API未返回有效BOM,需补充数据源。"] + elif isinstance(shortages, list) and shortages: evidence_lines = [shortage_material_names_line(shortages)] real_shortage_key = ( "真实缺料数量(每套需求×订单数量 + 存量需求数量 − 库存数量 − 待检数量 − 在途数量)" @@ -902,7 +821,6 @@ def lead_time_details( else: evidence_lines = ["- 缺料/BOM摘要:接口未返回可识别缺料汇总,需人工复核。"] - stock_review_lines = overdue_sales_order_lines(data) timestamp = data.get("时间戳") if isinstance(data.get("时间戳"), str) else None return { "prediction": prediction, @@ -915,12 +833,9 @@ def lead_time_details( "available_inventory": ( available_inventory if isinstance(available_inventory, (int, float)) else None ), - "stock_on_hand": stock_on_hand, - "production_required": production_required, - "stock_quantity_consistent": stock_quantity_consistent, - "lf_reducer_code": lf_reducer_code, - "lf_reducer_available": lf_reducer_available, - "stock_review_lines": stock_review_lines, + "requested_quantity": requested_quantity, + "shortage_data_available": shortage_data_available, + "reducer_shortages": reducer_shortages, "full_coverage": full_coverage, "evidence_lines": evidence_lines, "timestamp": timestamp, @@ -965,24 +880,11 @@ def overall_judgment_lines(candidates: list[dict[str, Any]]) -> list[str]: def candidate_report_lines(candidate: dict[str, Any], quantity: int) -> list[str]: details = candidate["details"] - lf_inventory_lines: list[str] = [] - if is_lf_model(candidate["model"]): - reducer_code = details.get("lf_reducer_code") - reducer_available = details.get("lf_reducer_available") - if isinstance(reducer_code, str) and reducer_available is not None: - lf_inventory_lines.append( - "- 来福减速器库存依据:" - f"物料编码{reducer_code};实际可用量{quantity_text(reducer_available)}件。" - ) - elif details.get("production_required") == 0: - lf_inventory_lines.append("- 来福库存门禁:整机现货已覆盖需求,无需减速器库存补充。") return [ f"{candidate['index']}. {candidate['model']}({candidate['type']})", f"- 需求数量:{quantity}台", f"- {details['prediction']}", - f"- 现货/排产情况:{details['inventory']}", - *lf_inventory_lines, - *details.get("stock_review_lines", []), + f"- 可用库存/覆盖情况:{details['inventory']}", f"- 主导因素:{details['main_factor']}", f"- 推荐理由:{candidate['reason']}", f"- 差异项:{candidate['difference']}", diff --git a/tests/test_feishu_bot_bridge.py b/tests/test_feishu_bot_bridge.py index 4af2b23..dc4e2fb 100644 --- a/tests/test_feishu_bot_bridge.py +++ b/tests/test_feishu_bot_bridge.py @@ -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):