2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-03-21 11:44:42 +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(

View File

@@ -37,6 +37,25 @@ test('Stock - Basic Tests', async ({ browser }) => {
await loadTab(page, 'Test Results');
await page.getByText('395c6d5586e5fb656901d047be27e1f7').waitFor();
await loadTab(page, 'Installed Items');
// Let's create a new stock item
await navigate(page, 'part/822/stock');
await page
.getByRole('button', { name: 'action-button-add-stock-item' })
.click();
await page
.getByRole('textbox', { name: 'number-field-quantity' })
.fill('987');
await page.getByRole('button', { name: 'Submit' }).click();
// Automatically navigate through to the newly created stock item
await page.getByText('Quantity: 987').first().waitFor();
await loadTab(page, 'Stock Tracking');
await page
.getByRole('cell', { name: 'Stock item created' })
.first()
.waitFor();
await page.getByRole('cell', { name: 'allaccess Ally Access' }).waitFor();
});
test('Stock - Location Tree', async ({ browser }) => {