From 16e00962f5f5b46cc09910ff0be2a5a5ee4ebf1e Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 28 Sep 2021 10:14:25 +1000 Subject: [PATCH] Override the "delete" behaviour for StockItem API - Mark for deletion instead of calling database delete - Returns (almost) instantly instead of hanging - Much better UI experience when performing bulk delete operations --- InvenTree/stock/api.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 017457f600..eaa65dd763 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -109,6 +109,17 @@ class StockDetail(generics.RetrieveUpdateDestroyAPIView): return super().update(request, *args, **kwargs) + def perform_destroy(self, instance): + """ + Instead of "deleting" the StockItem + (which may take a long time) + we instead schedule it for deletion at a later date. + + The background worker will delete these in the future + """ + + instance.mark_for_deletion() + class StockAdjust(APIView): """