From c4d7b248c4f05b5b05c41fef9e65ea8b59950e36 Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Thu, 26 Feb 2026 10:27:10 +0800 Subject: [PATCH] fix: improve component inventory insufficient error handling - Change component inventory insufficient from Error to Warning type in error report - Propagate productionOrderNo to M08_ComponentProcessor functions for proper error tracking - Update CheckComponentInventory to record warnings instead of errors for insufficient inventory - Pass productionOrderNo through ProcessComponentRecord call chain Changes: - M08_ComponentProcessor: Add productionOrderNo parameter to ProcessComponentRecord and CheckComponentInventory - M08_ComponentProcessor: Change insufficient inventory Record to RecordWarning - M08_ComponentProcessor: Use productionOrderNo in all error/warning recordings - M09_BOMExtractor: Pass productionOrderNo to ProcessComponentRecord call Co-Authored-By: Claude Sonnet 4.5 --- .../Modules/M08_ComponentProcessor.bas | 18 ++++++++++-------- VBA_BOMConverter/Modules/M09_BOMExtractor.bas | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/VBA_BOMConverter/Modules/M08_ComponentProcessor.bas b/VBA_BOMConverter/Modules/M08_ComponentProcessor.bas index 0291208..5e3831a 100644 --- a/VBA_BOMConverter/Modules/M08_ComponentProcessor.bas +++ b/VBA_BOMConverter/Modules/M08_ComponentProcessor.bas @@ -143,7 +143,8 @@ Public Function ProcessComponentRecord( _ ByVal params As Object, _ ByVal logger As clsErrorLogger, _ ByVal matchedRowNum As Long, _ - ByVal orderQty As Long _ + ByVal orderQty As Long, _ + ByVal productionOrderNo As String _ ) As Collection On Error GoTo ErrorHandler @@ -173,7 +174,7 @@ Public Function ProcessComponentRecord( _ Set headerMap = M07_BOMMatcher.BuildWorksheetHeaderMap(wsComponent) ' 步骤4: 检查部件库存 - If CheckComponentInventory(wsComponent, matchedRowNum, headerMap, orderQty) Then + If CheckComponentInventory(wsComponent, matchedRowNum, headerMap, orderQty, productionOrderNo) Then ' 库存充足,返回部件物料 Dim componentInfo As Object Set componentInfo = ExtractComponentInfo(wsComponent, matchedRowNum, headerMap, "部件") @@ -197,7 +198,7 @@ Public Function ProcessComponentRecord( _ ErrorHandler: If Not logger Is Nothing Then - logger.Record "", "M08.ProcessComponentRecord", "SystemError", _ + logger.Record productionOrderNo, "M08.ProcessComponentRecord", "SystemError", _ "处理部件记录失败: " & Err.Description, "" End If @@ -244,7 +245,8 @@ Private Function CheckComponentInventory( _ ByVal wsComponent As Worksheet, _ ByVal rowNum As Long, _ ByVal headerMap As Object, _ - ByVal orderQty As Long _ + ByVal orderQty As Long, _ + ByVal productionOrderNo As String _ ) As Boolean On Error GoTo ErrorHandler @@ -291,7 +293,7 @@ Private Function CheckComponentInventory( _ If g_InventoryDict Is Nothing Or Not g_InventoryDict.Exists(componentCode) Then ' 未找到库存数据,记录警告并返回False(库存不足) If Not g_Logger Is Nothing Then - g_Logger.RecordWarning "", "M08.CheckComponentInventory", "InventoryNotFound", _ + g_Logger.RecordWarning productionOrderNo, "M08.CheckComponentInventory", "InventoryNotFound", _ "部件[" & componentCode & "]未找到库存数据,视为库存不足", "" End If CheckComponentInventory = False @@ -319,9 +321,9 @@ Private Function CheckComponentInventory( _ g_AccumulatedDemandDict(componentCode) = totalDemand CheckComponentInventory = True Else - ' 库存不足,记录错误 + ' 库存不足,记录警告(不是错误) If Not g_Logger Is Nothing Then - g_Logger.Record "", "M08.CheckComponentInventory", "InsufficientInventory", _ + g_Logger.RecordWarning productionOrderNo, "M08.CheckComponentInventory", "InsufficientInventory", _ "部件[" & componentCode & "]库存不足。库存=" & stockQty & ", 累计需求=" & totalDemand, "" End If CheckComponentInventory = False @@ -331,7 +333,7 @@ Private Function CheckComponentInventory( _ ErrorHandler: If Not g_Logger Is Nothing Then - g_Logger.Record "", "M08.CheckComponentInventory", "SystemError", _ + g_Logger.Record productionOrderNo, "M08.CheckComponentInventory", "SystemError", _ "库存检查失败: " & Err.Description, "" End If ' 出错时返回False(库存不足) diff --git a/VBA_BOMConverter/Modules/M09_BOMExtractor.bas b/VBA_BOMConverter/Modules/M09_BOMExtractor.bas index 4a899d5..2176fb3 100644 --- a/VBA_BOMConverter/Modules/M09_BOMExtractor.bas +++ b/VBA_BOMConverter/Modules/M09_BOMExtractor.bas @@ -466,7 +466,7 @@ Private Function MatchAllMaterialTypesWithValidation( _ If bomMatchResult("success") Then Set componentMaterials = M08_ComponentProcessor.ProcessComponentRecord( _ - ws, params, logger, bomMatchResult("rowNums")(1), orderQty) + ws, params, logger, bomMatchResult("rowNums")(1), orderQty, productionOrderNo) Debug.Print " -> 返回物料数: " & componentMaterials.count End If