From c23f2828f5a32174528726ca323a7f6ce550c1df Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 1 Oct 2024 23:12:47 +1000 Subject: [PATCH] New event triggers (#8226) - When splitting a stock item - When moving a stock item --- src/backend/InvenTree/stock/models.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/backend/InvenTree/stock/models.py b/src/backend/InvenTree/stock/models.py index bf642ec6ee..efe335fd25 100644 --- a/src/backend/InvenTree/stock/models.py +++ b/src/backend/InvenTree/stock/models.py @@ -1921,6 +1921,8 @@ class StockItem( except Exception: pass + trigger_event('stockitem.split', id=new_stock.id, parent=self.id) + # Return a copy of the "new" stock item return new_stock @@ -1949,6 +1951,8 @@ class StockItem( status: If provided, override the status (default = existing status) packaging: If provided, override the packaging (default = existing packaging) """ + current_location = self.location + try: quantity = Decimal(kwargs.pop('quantity', self.quantity)) except InvalidOperation: @@ -2003,6 +2007,15 @@ class StockItem( self.save() + # Trigger event for the plugin system + trigger_event( + 'stockitem.moved', + id=self.id, + old_location=current_location.id if current_location else None, + new_location=location.id if location else None, + quantity=quantity, + ) + return True @transaction.atomic @@ -2032,6 +2045,7 @@ class StockItem( self.delete() return False + self.save() return True