Skip to content

Commit

Permalink
New event triggers (#8226)
Browse files Browse the repository at this point in the history
- When splitting a stock item
- When moving a stock item
  • Loading branch information
SchrodingersGat authored Oct 1, 2024
1 parent fe7bbc2 commit c23f282
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/backend/InvenTree/stock/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,8 @@ def splitStock(self, quantity, location=None, user=None, **kwargs):
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

Expand Down Expand Up @@ -1949,6 +1951,8 @@ def move(self, location, notes, user, **kwargs):
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:
Expand Down Expand Up @@ -2003,6 +2007,15 @@ def move(self, location, notes, user, **kwargs):

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
Expand Down Expand Up @@ -2032,6 +2045,7 @@ def updateQuantity(self, quantity):
self.delete()

return False

self.save()
return True

Expand Down

0 comments on commit c23f282

Please sign in to comment.