mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-07 06:00:57 +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:
|
for bom_item in trackable_parts:
|
||||||
valid_part_ids = valid_parts.get(bom_item.pk, [])
|
valid_part_ids = valid_parts.get(bom_item.pk, [])
|
||||||
|
|
||||||
items = stock.models.StockItem.objects.filter(
|
# Find all matching stock items, based on serial number
|
||||||
part__pk__in=valid_part_ids,
|
stock_items = list(
|
||||||
serial=output.serial,
|
stock.models.StockItem.objects.filter(
|
||||||
quantity=1,
|
part__pk__in=valid_part_ids,
|
||||||
).filter(stock.models.StockItem.IN_STOCK_FILTER)
|
serial=output.serial,
|
||||||
|
quantity=1,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if items.exists() and items.count() == 1:
|
# Filter stock items to only those which are in stock
|
||||||
stock_item = items[0]
|
# 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
|
# Find the 'BuildLine' object which points to this BomItem
|
||||||
try:
|
try:
|
||||||
|
@ -1592,13 +1592,17 @@ class StockItem(
|
|||||||
return self.children.count()
|
return self.children.count()
|
||||||
|
|
||||||
def is_in_stock(
|
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:
|
) -> bool:
|
||||||
"""Return True if this StockItem is "in stock".
|
"""Return True if this StockItem is "in stock".
|
||||||
|
|
||||||
Args:
|
Arguments:
|
||||||
check_status: If True, check the status of the StockItem. Defaults to True.
|
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_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:
|
if check_status and self.status not in StockStatusGroups.AVAILABLE_CODES:
|
||||||
return False
|
return False
|
||||||
@ -1606,6 +1610,9 @@ class StockItem(
|
|||||||
if check_quantity and self.quantity <= 0:
|
if check_quantity and self.quantity <= 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if check_in_production and self.is_building:
|
||||||
|
return False
|
||||||
|
|
||||||
return all([
|
return all([
|
||||||
self.sales_order is None, # Not assigned to a SalesOrder
|
self.sales_order is None, # Not assigned to a SalesOrder
|
||||||
self.belongs_to is None, # Not installed inside another StockItem
|
self.belongs_to is None, # Not installed inside another StockItem
|
||||||
|
Reference in New Issue
Block a user