Skip to content

Commit

Permalink
Bug fix: Manually create serialized stock (#8306)
Browse files Browse the repository at this point in the history
* Bug fix: Manually create serialized stock

- fixes bug which extraced location as a string, rather than the model instance

* Fix for StockList.create
  • Loading branch information
SchrodingersGat authored Oct 17, 2024
1 parent 9e0a4c6 commit 48dd3d3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/backend/InvenTree/stock/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,6 @@ def create(self, request, *args, **kwargs):
data.update(self.clean_data(request.data))

quantity = data.get('quantity', None)
location = data.get('location', None)

if quantity is None:
raise ValidationError({'quantity': _('Quantity is required')})
Expand All @@ -932,12 +931,10 @@ def create(self, request, *args, **kwargs):
except (ValueError, Part.DoesNotExist):
raise ValidationError({'part': _('Valid part must be supplied')})

# Set default location (if not provided)
if 'location' not in data:
location = part.get_default_location()

if location:
data['location'] = location.pk
location = data.get('location', None)
# Override location if not specified
if location is None and part.default_location:
data['location'] = part.default_location.pk

expiry_date = data.get('expiry_date', None)

Expand Down Expand Up @@ -1037,6 +1034,9 @@ def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=data)
serializer.is_valid(raise_exception=True)

# Extract location information
location = serializer.validated_data.get('location', None)

with transaction.atomic():
if serials:
# Create multiple serialized StockItem objects
Expand Down

0 comments on commit 48dd3d3

Please sign in to comment.