2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-04-05 19:10:54 +00:00

Save user info (#11572)

* Record user info when creating stock item

* Add unit test

* Add playwright test
This commit is contained in:
Oliver
2026-03-20 15:41:44 +11:00
committed by GitHub
parent 8c2592b3c2
commit fc730b9af7
3 changed files with 33 additions and 2 deletions

View File

@@ -1248,14 +1248,19 @@ class StockList(
else:
# Create a single StockItem object
# Note: This automatically creates a tracking entry
item = serializer.save()
item = StockItem(**serializer.validated_data)
if status_value and not item.compare_status(status_value):
item.set_status(status_value)
item.save(user=user)
item.refresh_from_db()
response_data = [serializer.data]
response_data = [
StockSerializers.StockItemSerializer(
item, context=self.get_serializer_context()
).data
]
return Response(
response_data,

View File

@@ -1417,12 +1417,19 @@ class StockItemTest(StockAPITestCase):
"""Test the default location functionality, if a 'location' is not specified in the creation request."""
# The part 'R_4K7_0603' (pk=4) has a default location specified
# Create a new StockItem instance
response = self.post(
self.list_url, data={'part': 4, 'quantity': 10}, expected_code=201
)
self.assertEqual(response.data[0]['location'], 2)
# Check that the item was associated with the correct user
item = StockItem.objects.get(pk=response.data[0]['pk'])
self.assertEqual(item.tracking_info_count, 1)
tracking = item.tracking_info.first()
self.assertEqual(tracking.user, self.user)
# What if we explicitly set the location to a different value?
response = self.post(