2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-01-10 05:08:09 +00:00

Tweak for auto allocation (#11106)

- Ensure only stock for "active" parts is considered
- Cleaner logic
This commit is contained in:
Oliver
2026-01-09 14:53:50 +11:00
committed by GitHub
parent 26f105fe88
commit 02a95ffba8
2 changed files with 15 additions and 6 deletions

View File

@@ -1326,7 +1326,7 @@ class Build(
# Check which parts we can "use" (may include variants and substitutes) # Check which parts we can "use" (may include variants and substitutes)
available_parts = bom_item.get_valid_parts_for_allocation( 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 # 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), key=lambda item, b=bom_item, v=variant_parts: stock_sort(item, b, v),
) )
if len(available_stock) == 0: if len(available_stock) == 1 or interchangeable:
# No stock items are available
continue
elif len(available_stock) == 1 or interchangeable:
# Either there is only a single stock item available, # Either there is only a single stock item available,
# or all items are "interchangeable" and we don't care where we take stock from # or all items are "interchangeable" and we don't care where we take stock from

View File

@@ -3832,10 +3832,18 @@ class BomItem(InvenTree.models.MetadataMixin, InvenTree.models.InvenTreeModel):
return assemblies return assemblies
def get_valid_parts_for_allocation( 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. """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: Includes:
- The referenced sub_part - The referenced sub_part
- Any directly specified substitute parts - Any directly specified substitute parts
@@ -3868,6 +3876,10 @@ class BomItem(InvenTree.models.MetadataMixin, InvenTree.models.InvenTreeModel):
if p.trackable != self.sub_part.trackable: if p.trackable != self.sub_part.trackable:
continue continue
# Filter by 'active' status
if not allow_inactive and not p.active:
continue
valid_parts.append(p) valid_parts.append(p)
return valid_parts return valid_parts