From 02a95ffba8d10cbb4cd4cbcb9207f88fd1baafca Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 9 Jan 2026 14:53:50 +1100 Subject: [PATCH] Tweak for auto allocation (#11106) - Ensure only stock for "active" parts is considered - Cleaner logic --- src/backend/InvenTree/build/models.py | 7 ++----- src/backend/InvenTree/part/models.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/backend/InvenTree/build/models.py b/src/backend/InvenTree/build/models.py index 2aed4fda01..2e7d30e34c 100644 --- a/src/backend/InvenTree/build/models.py +++ b/src/backend/InvenTree/build/models.py @@ -1326,7 +1326,7 @@ class Build( # Check which parts we can "use" (may include variants and substitutes) available_parts = bom_item.get_valid_parts_for_allocation( - allow_variants=True, allow_substitutes=substitutes + allow_variants=True, allow_inactive=False, allow_substitutes=substitutes ) # Look for available stock items @@ -1369,10 +1369,7 @@ class Build( key=lambda item, b=bom_item, v=variant_parts: stock_sort(item, b, v), ) - if len(available_stock) == 0: - # No stock items are available - continue - elif len(available_stock) == 1 or interchangeable: + if len(available_stock) == 1 or interchangeable: # Either there is only a single stock item available, # or all items are "interchangeable" and we don't care where we take stock from diff --git a/src/backend/InvenTree/part/models.py b/src/backend/InvenTree/part/models.py index e1a4342f29..74296eede6 100644 --- a/src/backend/InvenTree/part/models.py +++ b/src/backend/InvenTree/part/models.py @@ -3832,10 +3832,18 @@ class BomItem(InvenTree.models.MetadataMixin, InvenTree.models.InvenTreeModel): return assemblies def get_valid_parts_for_allocation( - self, allow_variants=True, allow_substitutes=True + self, + allow_variants: bool = True, + allow_substitutes: bool = True, + allow_inactive: bool = True, ): """Return a list of valid parts which can be allocated against this BomItem. + Arguments: + allow_variants: If True, include variants of the sub_part + allow_substitutes: If True, include any directly specified substitute parts + allow_inactive: If True, include inactive parts in the returned list + Includes: - The referenced sub_part - Any directly specified substitute parts @@ -3868,6 +3876,10 @@ class BomItem(InvenTree.models.MetadataMixin, InvenTree.models.InvenTreeModel): if p.trackable != self.sub_part.trackable: continue + # Filter by 'active' status + if not allow_inactive and not p.active: + continue + valid_parts.append(p) return valid_parts