From 67aac9c373a5768f1770f35a7209af62d01529bb Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 10 Jan 2022 09:07:30 +1100 Subject: [PATCH] Add triggere events for the "company" app --- InvenTree/company/models.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index ef3c8aad2e..3c90ef6e2d 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -11,6 +11,8 @@ 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 @@ -33,6 +35,8 @@ 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 @@ -267,6 +271,15 @@ class Company(models.Model): return self.purchase_orders.filter(status__in=PurchaseOrderStatus.FAILED) +@receiver(post_save, sender=Company, dispatch_uid='company_post_save_log') +def after_save_company(sender, instance: Company, created: bool, **kwargs): + + if created: + trigger_event('company.created', company_id=instance.pk) + else: + trigger_event('company.saved', company_id=instance.pk) + + class Contact(models.Model): """ A Contact represents a person who works at a particular company. A Company may have zero or more associated Contact objects. @@ -386,6 +399,15 @@ class ManufacturerPart(models.Model): return s +@receiver(post_save, sender=ManufacturerPart, dispatch_uid='manufacturerpart_post_save_log') +def after_save_manufacturer_part(sender, instance: ManufacturerPart, created: bool, **kwargs): + + if created: + trigger_event('manufacturerpart.created', manufacturer_part_id=instance.pk) + else: + trigger_event('manufacturerpart.saved', manufacturer_part_id=instance.pk) + + class ManufacturerPartParameter(models.Model): """ A ManufacturerPartParameter represents a key:value parameter for a MnaufacturerPart. @@ -686,6 +708,15 @@ class SupplierPart(models.Model): return s +@receiver(post_save, sender=SupplierPart, dispatch_uid='supplierpart_post_save_log') +def after_save_supplier_part(sender, instance: SupplierPart, created: bool, **kwargs): + + if created: + trigger_event('supplierpart.created', supplier_part_id=instance.pk) + else: + trigger_event('supplierpart.saved', supplier_part_id=instance.pk) + + class SupplierPriceBreak(common.models.PriceBreak): """ Represents a quantity price break for a SupplierPart. - Suppliers can offer discounts at larger quantities