diff --git a/src/backend/InvenTree/stock/tests.py b/src/backend/InvenTree/stock/tests.py index 27548c3806b..c83e6bf274e 100644 --- a/src/backend/InvenTree/stock/tests.py +++ b/src/backend/InvenTree/stock/tests.py @@ -951,6 +951,45 @@ def test_merge(self): # Final purchase price should be the weighted average self.assertAlmostEqual(s1.purchase_price.amount, 16.875, places=3) + def test_notify_low_stock(self): + """Test that the 'notify_low_stock' task is triggered correctly.""" + FUNC_NAME = 'part.tasks.notify_low_stock_if_required' + + from django_q.models import OrmQ + + # Start from a blank slate + OrmQ.objects.all().delete() + + def check_func() -> bool: + """Check that the 'notify_low_stock_if_required' task has been triggered.""" + found = False + for task in OrmQ.objects.all(): + if task.func() == FUNC_NAME: + found = True + break + + # Clear the task queue (for the next test) + OrmQ.objects.all().delete() + + return found + + self.assertFalse(check_func()) + + part = Part.objects.first() + + # Create a new stock item for this part + item = StockItem.objects.create( + part=part, quantity=100, location=StockLocation.objects.first() + ) + + self.assertTrue(check_func()) + self.assertFalse(check_func()) + + # Re-count the stock item + item.stocktake(99, None) + + self.assertTrue(check_func()) + class StockBarcodeTest(StockTestBase): """Run barcode tests for the stock app."""