2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-30 16:41:35 +00:00

Custom event when bulk-creating items (#10063)

This commit is contained in:
Oliver
2025-07-23 22:17:07 +10:00
committed by GitHub
parent dfd9fe44a4
commit d563db6e7e
2 changed files with 12 additions and 1 deletions

View File

@@ -14,3 +14,5 @@ class StockEvents(BaseEventEnum):
ITEM_COUNTED = 'stockitem.counted'
ITEM_QUANTITY_UPDATED = 'stockitem.quantityupdated'
ITEM_INSTALLED_INTO_ASSEMBLY = 'stockitem.installed'
ITEMS_CREATED = 'stockitem.created_items'

View File

@@ -650,8 +650,17 @@ class StockItem(
)
stock.tasks.rebuild_stock_item_tree(parent.tree_id)
# Fetch the new StockItem objects from the database
items = StockItem.objects.filter(part=part, serial__in=serials)
# Trigger a 'created' event for the new items
# Note that instead of a single event for each item,
# we trigger a single event for all items created
stock_ids = list(items.values_list('id', flat=True).distinct())
trigger_event(StockEvents.ITEMS_CREATED, ids=stock_ids)
# Return the newly created StockItem objects
return StockItem.objects.filter(part=part, serial__in=serials)
return items
@staticmethod
def convert_serial_to_int(serial: str) -> int: