2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 19:46:46 +00:00

New event triggers (#8226)

- When splitting a stock item
- When moving a stock item
This commit is contained in:
Oliver 2024-10-01 23:12:47 +10:00 committed by GitHub
parent fe7bbc2436
commit c23f2828f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1921,6 +1921,8 @@ class StockItem(
except Exception: except Exception:
pass pass
trigger_event('stockitem.split', id=new_stock.id, parent=self.id)
# Return a copy of the "new" stock item # Return a copy of the "new" stock item
return new_stock return new_stock
@ -1949,6 +1951,8 @@ class StockItem(
status: If provided, override the status (default = existing status) status: If provided, override the status (default = existing status)
packaging: If provided, override the packaging (default = existing packaging) packaging: If provided, override the packaging (default = existing packaging)
""" """
current_location = self.location
try: try:
quantity = Decimal(kwargs.pop('quantity', self.quantity)) quantity = Decimal(kwargs.pop('quantity', self.quantity))
except InvalidOperation: except InvalidOperation:
@ -2003,6 +2007,15 @@ class StockItem(
self.save() 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 return True
@transaction.atomic @transaction.atomic
@ -2032,6 +2045,7 @@ class StockItem(
self.delete() self.delete()
return False return False
self.save() self.save()
return True return True