mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Unit test fixes
This commit is contained in:
parent
918106c225
commit
5ab4be7025
@ -1305,7 +1305,6 @@ class StockItem(MPTTModel):
|
||||
|
||||
self.quantity = quantity
|
||||
|
||||
|
||||
if quantity == 0 and self.delete_on_deplete and self.can_delete():
|
||||
self.mark_for_deletion()
|
||||
|
||||
|
@ -30,6 +30,6 @@ def delete_old_stock_items():
|
||||
|
||||
items = StockItem.objects.filter(scheduled_for_deletion=True)
|
||||
|
||||
if items.count() > 0:
|
||||
logger.info(f"Removing {items.count()} StockItem objects scheduled for deletion")
|
||||
|
||||
items.delete()
|
||||
|
@ -332,6 +332,8 @@ class StockTest(TestCase):
|
||||
w1 = StockItem.objects.get(pk=100)
|
||||
w2 = StockItem.objects.get(pk=101)
|
||||
|
||||
self.assertFalse(w2.scheduled_for_depletion)
|
||||
|
||||
# Take 25 units from w1 (there are only 10 in stock)
|
||||
w1.take_stock(30, None, notes='Took 30')
|
||||
|
||||
@ -342,6 +344,16 @@ class StockTest(TestCase):
|
||||
# Take 25 units from w2 (will be deleted)
|
||||
w2.take_stock(30, None, notes='Took 30')
|
||||
|
||||
# w2 should now be marked for future deletion
|
||||
w2 = StockItem.objects.get(pk=101)
|
||||
self.assertTrue(w2.scheduled_for_depletion)
|
||||
|
||||
from stock.tasks import delete_old_stock_items
|
||||
|
||||
# Now run the "background task" to delete these stock items
|
||||
delete_old_stock_items()
|
||||
|
||||
# This StockItem should now have been deleted
|
||||
with self.assertRaises(StockItem.DoesNotExist):
|
||||
w2 = StockItem.objects.get(pk=101)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user