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:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user