refactor: add subcategory fallback logic for material filtering

Refactored the material retrieval logic in GetMaterialsByModel to
automatically search within subcategories if no matches are found in the
specified parent category.

- Added FilterCategoryWithSubcategories helper function to handle recursive
  searching and fallback logic.
- Restructured main function to delegate filtering to the new helper.
- Enhanced code comments to clarify the step-by-step matching process.
This commit is contained in:
Misaka_Company
2026-01-20 15:31:43 +08:00
parent 7f89f37f35
commit 388ccc4e7a
2 changed files with 117 additions and 27 deletions

View File

@@ -80,12 +80,14 @@ Sub Example1_GeneratePickingListByModel()
Dim j As Long
For j = 1 To materials.Count
Set mat = materials(j)
wsPickList.Cells(row, 1).value = cat.categoryName
' 使用物料自己的Category属性而不是外层循环的类别名称
' 这样当GetMaterialsByModel降级到子类别查找时能正确显示子类别名称
wsPickList.Cells(row, 1).value = mat.Category
wsPickList.Cells(row, 2).value = mat.code
wsPickList.Cells(row, 3).value = mat.Name
wsPickList.Cells(row, 4).value = mat.Quantity
wsPickList.Cells(row, 5).value = IIf(mat.Condition = "", "(无条件)", mat.Condition)
wsPickList.Cells(row, 6).value = "?"
wsPickList.Cells(row, 6).value = ""
row = row + 1
Next j
Next i