Event refactoring

This commit is contained in:
Oliver 2022-01-10 17:28:44 +11:00
parent 886b1f1d72
commit 1243923944
6 changed files with 12 additions and 41 deletions

View File

@ -587,17 +587,8 @@ class Build(MPTTModel, ReferenceIndexingMixin):
# which point to thie Build Order
self.allocated_stock.all().delete()
if user:
user_id = user.pk
else:
user_id = None
# Register an event
trigger_event(
'build.completed',
build_id=self.pk,
user_id=user_id,
)
trigger_event('build.completed', id=self.pk)
@transaction.atomic
def cancelBuild(self, user):
@ -618,16 +609,7 @@ class Build(MPTTModel, ReferenceIndexingMixin):
self.status = BuildStatus.CANCELLED
self.save()
if user:
user_id = user.pk
else:
user_id = None
trigger_event(
'build.cancelled',
build_id=self.pk,
user_id=user_id,
)
trigger_event('build.cancelled', id=self.pk)
@transaction.atomic
def unallocateStock(self, bom_item=None, output=None):

View File

@ -11,8 +11,6 @@ from django.utils.translation import ugettext_lazy as _
from django.core.validators import MinValueValidator
from django.core.exceptions import ValidationError
from django.db.models.signals import post_save
from django.dispatch.dispatcher import receiver
from django.db import models
from django.db.models import Sum, Q, UniqueConstraint
@ -35,8 +33,6 @@ import common.models
import common.settings
from common.settings import currency_code_default
from plugin.events import trigger_event
def rename_company_image(instance, filename):
""" Function to rename a company image after upload

View File

@ -11,8 +11,7 @@ from decimal import Decimal
from django.db import models, transaction
from django.db.models import Q, F, Sum
from django.db.models.functions import Coalesce
from django.db.models.signals import post_save
from django.dispatch.dispatcher import receiver
from django.core.validators import MinValueValidator
from django.core.exceptions import ValidationError
from django.contrib.auth.models import User
@ -320,7 +319,7 @@ class PurchaseOrder(Order):
self.issue_date = datetime.now().date()
self.save()
trigger_event('purchaseorder.placed', order_id=self.pk)
trigger_event('purchaseorder.placed', id=self.pk)
@transaction.atomic
def complete_order(self):
@ -331,7 +330,7 @@ class PurchaseOrder(Order):
self.complete_date = datetime.now().date()
self.save()
trigger_event('purchaseorder.completed', order_id=self.pk)
trigger_event('purchaseorder.completed', id=self.pk)
@property
def is_overdue(self):
@ -363,7 +362,7 @@ class PurchaseOrder(Order):
self.status = PurchaseOrderStatus.CANCELLED
self.save()
trigger_event('purchaseorder.cancelled', order_id=self.pk)
trigger_event('purchaseorder.cancelled', id=self.pk)
def pending_line_items(self):
""" Return a list of pending line items for this order.
@ -676,7 +675,7 @@ class SalesOrder(Order):
self.save()
trigger_event('salesorder.completed', order_id=self.pk)
trigger_event('salesorder.completed', id=self.pk)
return True
@ -709,7 +708,7 @@ class SalesOrder(Order):
for allocation in line.allocations.all():
allocation.delete()
trigger_event('salesorder.cancelled', order_id=self.pk)
trigger_event('salesorder.cancelled', id=self.pk)
return True
@ -1117,7 +1116,7 @@ class SalesOrderShipment(models.Model):
self.save()
trigger_event('salesordershipment.completed', shipment_id=self.pk)
trigger_event('salesordershipment.completed', id=self.pk)
class SalesOrderAllocation(models.Model):

View File

@ -60,8 +60,6 @@ import common.models
import part.settings as part_settings
from plugin.events import trigger_event
logger = logging.getLogger("inventree")

View File

@ -91,10 +91,6 @@ def process_event(plugin_slug, event, *args, **kwargs):
plugin.process_event(event, *args, **kwargs)
"""
Register some default event triggers on model signals
"""
@receiver(post_save)
def after_save(sender, instance, created, **kwargs):
"""

View File

@ -722,8 +722,8 @@ class StockItem(MPTTModel):
trigger_event(
'stockitem.assignedtocustomer',
item_id=self.id,
customer_id=customer.id,
id=self.id,
customer=customer.id,
)
# Return the reference to the stock item
@ -755,7 +755,7 @@ class StockItem(MPTTModel):
trigger_event(
'stockitem.returnedfromcustomer',
item_id=self.id,
id=self.id,
)
self.save()