From c174cf12a533ff52f5116b357b5dcfff5da07309 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 9 Jan 2026 15:07:23 +1100 Subject: [PATCH] Tweak for auto allocation (#11106) (#11107) - Ensure only stock for "active" parts is considered - Cleaner logic (cherry picked from commit 02a95ffba8d10cbb4cd4cbcb9207f88fd1baafca) Co-authored-by: Oliver --- 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 e4c89c5d63..da73276ba5 100644 --- a/src/backend/InvenTree/build/models.py +++ b/src/backend/InvenTree/build/models.py @@ -1325,7 +1325,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 @@ -1368,10 +1368,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 16e8476413..5953a6e6a0 100644 --- a/src/backend/InvenTree/part/models.py +++ b/src/backend/InvenTree/part/models.py @@ -4247,10 +4247,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 @@ -4283,6 +4291,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