mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-02 19:50:59 +00:00
Implement structural stock locations (#3949)
* Implement structural stock locations * Bumped API version
This commit is contained in:
@ -6,6 +6,7 @@ from datetime import datetime, timedelta
|
||||
from enum import IntEnum
|
||||
|
||||
import django.http
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.urls import reverse
|
||||
|
||||
import tablib
|
||||
@ -225,6 +226,71 @@ class StockLocationTest(StockAPITestCase):
|
||||
child.refresh_from_db()
|
||||
self.assertEqual(child.parent, parent_stock_location)
|
||||
|
||||
def test_stock_location_structural(self):
|
||||
"""Test the effectiveness of structural stock locations
|
||||
|
||||
Make sure:
|
||||
- Stock items cannot be created in structural locations
|
||||
- Stock items cannot be located to structural locations
|
||||
- Check that stock location change to structural fails if items located into it
|
||||
"""
|
||||
|
||||
# Create our structural stock location
|
||||
structural_location = StockLocation.objects.create(
|
||||
name='Structural stock location',
|
||||
description='This is the structural stock location',
|
||||
parent=None,
|
||||
structural=True
|
||||
)
|
||||
|
||||
stock_item_count_before = StockItem.objects.count()
|
||||
|
||||
# Make sure that we get an error if we try to create a stock item in the structural location
|
||||
with self.assertRaises(ValidationError):
|
||||
item = StockItem.objects.create(
|
||||
batch="Stock item which shall not be created",
|
||||
location=structural_location
|
||||
)
|
||||
|
||||
# Ensure that the stock item really did not get created in the structural location
|
||||
self.assertEqual(stock_item_count_before, StockItem.objects.count())
|
||||
|
||||
# Create a non-structural location for test stock location change
|
||||
non_structural_location = StockLocation.objects.create(
|
||||
name='Non-structural category',
|
||||
description='This is a non-structural category',
|
||||
parent=None,
|
||||
structural=False
|
||||
)
|
||||
|
||||
# Construct a part for stock item creation
|
||||
part = Part.objects.create(
|
||||
name='Part for stock item creation', description='Part for stock item creation',
|
||||
category=None,
|
||||
is_template=False,
|
||||
)
|
||||
|
||||
# Create the test stock item located to a non-structural category
|
||||
item = StockItem.objects.create(
|
||||
batch="Item which will be tried to relocated to a structural location",
|
||||
location=non_structural_location,
|
||||
part=part
|
||||
)
|
||||
|
||||
# Try to relocate it to a structural location
|
||||
item.location = structural_location
|
||||
with self.assertRaises(ValidationError):
|
||||
item.save()
|
||||
|
||||
# Ensure that the item did not get saved to the DB
|
||||
item.refresh_from_db()
|
||||
self.assertEqual(item.location.pk, non_structural_location.pk)
|
||||
|
||||
# Try to change the non-structural location to structural while items located into it
|
||||
non_structural_location.structural = True
|
||||
with self.assertRaises(ValidationError):
|
||||
non_structural_location.full_clean()
|
||||
|
||||
|
||||
class StockItemListTest(StockAPITestCase):
|
||||
"""Tests for the StockItem API LIST endpoint."""
|
||||
|
Reference in New Issue
Block a user