Skip to content

Commit d563db6

Browse files
Custom event when bulk-creating items (#10063)
1 parent dfd9fe4 commit d563db6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/backend/InvenTree/stock/events.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ class StockEvents(BaseEventEnum):
1414
ITEM_COUNTED = 'stockitem.counted'
1515
ITEM_QUANTITY_UPDATED = 'stockitem.quantityupdated'
1616
ITEM_INSTALLED_INTO_ASSEMBLY = 'stockitem.installed'
17+
18+
ITEMS_CREATED = 'stockitem.created_items'

src/backend/InvenTree/stock/models.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,17 @@ def _create_serial_numbers(cls, serials: list, **kwargs) -> QuerySet:
650650
)
651651
stock.tasks.rebuild_stock_item_tree(parent.tree_id)
652652

653+
# Fetch the new StockItem objects from the database
654+
items = StockItem.objects.filter(part=part, serial__in=serials)
655+
656+
# Trigger a 'created' event for the new items
657+
# Note that instead of a single event for each item,
658+
# we trigger a single event for all items created
659+
stock_ids = list(items.values_list('id', flat=True).distinct())
660+
trigger_event(StockEvents.ITEMS_CREATED, ids=stock_ids)
661+
653662
# Return the newly created StockItem objects
654-
return StockItem.objects.filter(part=part, serial__in=serials)
663+
return items
655664

656665
@staticmethod
657666
def convert_serial_to_int(serial: str) -> int:

0 commit comments

Comments
 (0)