mirror of
https://github.com/inventree/InvenTree.git
synced 2026-08-19 19:49:48 +00:00
- Check that underlying part is still available
(cherry picked from commit f1e6ec249d)
Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
co-authored by
Oliver
parent
8823b66e32
commit
4a1887c76c
@@ -1040,15 +1040,27 @@ class SupplierPriceBreak(common.models.PriceBreak):
|
||||
)
|
||||
def after_save_supplier_price(sender, instance, created, **kwargs):
|
||||
"""Callback function when a SupplierPriceBreak is created or updated."""
|
||||
if (
|
||||
(
|
||||
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
|
||||
and not InvenTree.ready.isImportingData()
|
||||
)
|
||||
and instance.part
|
||||
and instance.part.part
|
||||
):
|
||||
instance.part.part.schedule_pricing_update(create=True)
|
||||
from part.models import Part
|
||||
|
||||
if not InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING):
|
||||
return
|
||||
|
||||
if InvenTree.ready.isImportingData():
|
||||
return
|
||||
|
||||
try:
|
||||
supplier_part = instance.part
|
||||
except SupplierPart.DoesNotExist:
|
||||
# The underlying SupplierPart instance has been deleted
|
||||
return
|
||||
|
||||
try:
|
||||
base_part = supplier_part.part
|
||||
except Part.DoesNotExist:
|
||||
# The underlying Part instance has been deleted
|
||||
return
|
||||
|
||||
base_part.schedule_pricing_update(create=True)
|
||||
|
||||
|
||||
@receiver(
|
||||
@@ -1058,12 +1070,24 @@ def after_save_supplier_price(sender, instance, created, **kwargs):
|
||||
)
|
||||
def after_delete_supplier_price(sender, instance, **kwargs):
|
||||
"""Callback function when a SupplierPriceBreak is deleted."""
|
||||
if (
|
||||
(
|
||||
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
|
||||
and not InvenTree.ready.isImportingData()
|
||||
)
|
||||
and instance.part
|
||||
and instance.part.part
|
||||
):
|
||||
instance.part.part.schedule_pricing_update(create=False)
|
||||
from part.models import Part
|
||||
|
||||
if not InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING):
|
||||
return
|
||||
|
||||
if InvenTree.ready.isImportingData():
|
||||
return
|
||||
|
||||
try:
|
||||
supplier_part = instance.part
|
||||
except SupplierPart.DoesNotExist:
|
||||
# The underlying SupplierPart instance has been deleted
|
||||
return
|
||||
|
||||
try:
|
||||
base_part = supplier_part.part
|
||||
except Part.DoesNotExist:
|
||||
# The underlying Part instance has been deleted
|
||||
return
|
||||
|
||||
base_part.schedule_pricing_update(create=False)
|
||||
|
||||
@@ -2953,23 +2953,32 @@ class StockItem(
|
||||
def after_delete_stock_item(sender, instance: StockItem, **kwargs):
|
||||
"""Function to be executed after a StockItem object is deleted."""
|
||||
from part import tasks as part_tasks
|
||||
from part.models import Part
|
||||
|
||||
if InvenTree.ready.isImportingData():
|
||||
return
|
||||
|
||||
try:
|
||||
base_part = instance.part
|
||||
except Part.DoesNotExist:
|
||||
return
|
||||
|
||||
if not base_part:
|
||||
# Base part does not exist, or has been deleted
|
||||
return
|
||||
|
||||
if InvenTree.ready.canAppAccessDatabase(allow_test=True):
|
||||
# Run this check in the background
|
||||
InvenTree.tasks.offload_task(
|
||||
part_tasks.notify_low_stock_if_required,
|
||||
instance.part.pk,
|
||||
base_part.pk,
|
||||
group='notification',
|
||||
force_async=True,
|
||||
)
|
||||
|
||||
if InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING):
|
||||
# Schedule an update on parent part pricing
|
||||
if instance.part:
|
||||
instance.part.schedule_pricing_update(create=False)
|
||||
base_part.schedule_pricing_update(create=False)
|
||||
|
||||
|
||||
@receiver(post_save, sender=StockItem, dispatch_uid='stock_item_post_save_log')
|
||||
|
||||
Reference in New Issue
Block a user