From 01191d84c56ba7094d7e26a18c79377c8db72f79 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 4 Nov 2021 14:32:42 +1100 Subject: [PATCH] Only run check stock function when updating an existing part --- InvenTree/build/models.py | 2 -- InvenTree/build/tasks.py | 2 -- InvenTree/part/models.py | 9 ++++++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index e8263285b1..0dd6a404e5 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -8,8 +8,6 @@ import decimal import os from datetime import datetime -from django import dispatch - from django.contrib.auth.models import User from django.core.exceptions import ValidationError diff --git a/InvenTree/build/tasks.py b/InvenTree/build/tasks.py index 8b5a0a1831..7455d6eac2 100644 --- a/InvenTree/build/tasks.py +++ b/InvenTree/build/tasks.py @@ -9,8 +9,6 @@ from django.template.loader import render_to_string from allauth.account.models import EmailAddress -from common.models import NotificationEntry - import build.models import InvenTree.helpers import InvenTree.tasks diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 7a15657a90..f37b61864d 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -2102,13 +2102,16 @@ class Part(MPTTModel): @receiver(post_save, sender=Part, dispatch_uid='part_post_save_log') -def after_save_part(sender, instance: Part, **kwargs): +def after_save_part(sender, instance: Part, created, **kwargs): """ Function to be executed after a Part is saved """ - # Run this check in the background - InvenTree.tasks.offload_task('part.tasks.notify_low_stock_if_required', instance) + if not created: + # Check part stock only if we are *updating* the part (not creating it) + + # Run this check in the background + InvenTree.tasks.offload_task('part.tasks.notify_low_stock_if_required', instance) def attach_file(instance, filename):