mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-06 21:50:55 +00:00
Tweak "auto_allocate" serial numbers (#9942)
- Allow "in production" items - Enables allocation of child builds
This commit is contained in:
@ -938,14 +938,24 @@ class Build(
|
||||
for bom_item in trackable_parts:
|
||||
valid_part_ids = valid_parts.get(bom_item.pk, [])
|
||||
|
||||
items = stock.models.StockItem.objects.filter(
|
||||
part__pk__in=valid_part_ids,
|
||||
serial=output.serial,
|
||||
quantity=1,
|
||||
).filter(stock.models.StockItem.IN_STOCK_FILTER)
|
||||
# Find all matching stock items, based on serial number
|
||||
stock_items = list(
|
||||
stock.models.StockItem.objects.filter(
|
||||
part__pk__in=valid_part_ids,
|
||||
serial=output.serial,
|
||||
quantity=1,
|
||||
)
|
||||
)
|
||||
|
||||
if items.exists() and items.count() == 1:
|
||||
stock_item = items[0]
|
||||
# Filter stock items to only those which are in stock
|
||||
# Note that we can accept "in production" items here
|
||||
available_items = filter(
|
||||
lambda item: item.is_in_stock(check_in_production=False),
|
||||
stock_items,
|
||||
)
|
||||
|
||||
if len(available_items) == 1:
|
||||
stock_item = available_items[0]
|
||||
|
||||
# Find the 'BuildLine' object which points to this BomItem
|
||||
try:
|
||||
|
@ -1592,13 +1592,17 @@ class StockItem(
|
||||
return self.children.count()
|
||||
|
||||
def is_in_stock(
|
||||
self, check_status: bool = True, check_quantity: bool = True
|
||||
self,
|
||||
check_status: bool = True,
|
||||
check_quantity: bool = True,
|
||||
check_in_production: bool = True,
|
||||
) -> bool:
|
||||
"""Return True if this StockItem is "in stock".
|
||||
|
||||
Args:
|
||||
Arguments:
|
||||
check_status: If True, check the status of the StockItem. Defaults to True.
|
||||
check_quantity: If True, check the quantity of the StockItem. Defaults to True.
|
||||
check_in_production: If True, check if the item is in production. Defaults to True.
|
||||
"""
|
||||
if check_status and self.status not in StockStatusGroups.AVAILABLE_CODES:
|
||||
return False
|
||||
@ -1606,6 +1610,9 @@ class StockItem(
|
||||
if check_quantity and self.quantity <= 0:
|
||||
return False
|
||||
|
||||
if check_in_production and self.is_building:
|
||||
return False
|
||||
|
||||
return all([
|
||||
self.sales_order is None, # Not assigned to a SalesOrder
|
||||
self.belongs_to is None, # Not installed inside another StockItem
|
||||
|
Reference in New Issue
Block a user