Improve filter for auto-allocation of build item (#3603)

This commit is contained in:
Oliver 2022-08-24 15:37:58 +10:00 committed by GitHub
parent 978d18d01b
commit 349bbb8545
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -674,28 +674,26 @@ class Build(MPTTModel, ReferenceIndexingMixin):
parts = bom_item.get_valid_parts_for_allocation() parts = bom_item.get_valid_parts_for_allocation()
for part in parts: items = StockModels.StockItem.objects.filter(
part__in=parts,
serial=str(serial),
quantity=1,
).filter(StockModels.StockItem.IN_STOCK_FILTER)
items = StockModels.StockItem.objects.filter( """
part=part, Test if there is a matching serial number!
serial=str(serial), """
if items.exists() and items.count() == 1:
stock_item = items[0]
# Allocate the stock item
BuildItem.objects.create(
build=self,
bom_item=bom_item,
stock_item=stock_item,
quantity=1, quantity=1,
).filter(StockModels.StockItem.IN_STOCK_FILTER) install_into=output,
)
"""
Test if there is a matching serial number!
"""
if items.exists() and items.count() == 1:
stock_item = items[0]
# Allocate the stock item
BuildItem.objects.create(
build=self,
bom_item=bom_item,
stock_item=stock_item,
quantity=1,
install_into=output,
)
else: else:
"""Create a single build output of the given quantity.""" """Create a single build output of the given quantity."""