2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-13 08:21:26 +00:00

Add "expiry_date" field to StockItem model

- Also adds "is_expired" function
This commit is contained in:
Oliver Walters
2021-01-03 23:56:35 +11:00
parent fe3d4a9867
commit 07cda765f0
3 changed files with 89 additions and 27 deletions

View File

@ -49,6 +49,40 @@ class StockTest(TestCase):
Part.objects.rebuild()
StockItem.objects.rebuild()
def test_expiry(self):
"""
Test expiry date functionality for StockItem model.
"""
today = datetime.datetime.now().date()
item = StockItem.objects.create(
location=self.office,
part=Part.objects.get(pk=1),
quantity=10,
)
# Without an expiry_date set, item should not be "expired"
self.assertFalse(item.is_expired())
# Set the expiry date to today
item.expiry_date = today
item.save()
self.assertFalse(item.is_expired())
# Set the expiry date in the future
item.expiry_date = today + datetime.timedelta(days=5)
item.save()
self.assertFalse(item.is_expired())
# Set the expiry date in the past
item.expiry_date = today - datetime.timedelta(days=5)
item.save()
self.assertTrue(item.is_expired())
def test_is_building(self):
"""
Test that the is_building flag does not count towards stock.