2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 03:00:54 +00:00

Add some unit testing

This commit is contained in:
Oliver Walters
2020-10-05 00:29:06 +11:00
parent 26d113e8ad
commit fe3a72c6cc
3 changed files with 33 additions and 4 deletions

View File

@ -721,6 +721,10 @@ class StockItem(MPTTModel):
if self.customer is not None:
return False
# Not 'in stock' if it is building
if self.is_building:
return False
# Not 'in stock' if the status code makes it unavailable
if self.status in StockStatus.UNAVAILABLE_CODES:
return False

View File

@ -47,6 +47,30 @@ class StockTest(TestCase):
Part.objects.rebuild()
StockItem.objects.rebuild()
def test_is_building(self):
"""
Test that the is_building flag does not count towards stock.
"""
part = Part.objects.get(pk=1)
# Record the total stock count
n = part.total_stock
StockItem.objects.create(part=part, quantity=5)
# And there should be *no* items being build
self.assertEqual(part.quantity_being_built, 0)
# Add some stock items which are "building"
for i in range(10):
item = StockItem.objects.create(part=part, quantity=10, is_building=True)
# The "is_building" quantity should not be counted here
self.assertEqual(part.total_stock, n + 5)
self.assertEqual(part.quantity_being_built, 100)
def test_loc_count(self):
self.assertEqual(StockLocation.objects.count(), 7)