use new helper func (#12373)

This commit is contained in:
Oliver 2026-07-13 18:54:10 +10:00 committed by GitHub
parent 431a6e49a0
commit a12fd546ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 5 deletions

View File

@ -42,6 +42,7 @@ from generic.enums import StringEnum
from generic.states import StatusCodeMixin
from generic.states.fields import InvenTreeCustomStatusModelField
from InvenTree.fields import InvenTreeModelMoneyField, InvenTreeURLField
from InvenTree.helpers_db import bulk_create_and_fetch
from InvenTree.status_codes import (
SalesOrderStatusGroups,
StockHistoryCode,
@ -709,7 +710,6 @@ class StockItem(
if 'part' not in data:
raise ValidationError({'part': _('Part must be specified')})
part = data['part']
parent = kwargs.pop('parent', None) or data.get('parent')
data['parent'] = parent
@ -729,10 +729,7 @@ class StockItem(
items.append(StockItem(**data))
# Create the StockItem objects in bulk
StockItem.objects.bulk_create(items, batch_size=250)
# Fetch the new StockItem objects from the database
items = StockItem.objects.filter(part=part, serial__in=serials)
items = bulk_create_and_fetch(StockItem, items)
# Trigger a 'created' event for the new items
# Note that instead of a single event for each item,