mirror of
https://github.com/inventree/InvenTree.git
synced 2026-08-10 15:36:17 +00:00
[bug] Fix post-delete actions (#12575)
- Check that underlying part is still available
This commit is contained in:
@@ -1044,15 +1044,27 @@ class SupplierPriceBreak(common.models.PriceBreak):
|
|||||||
)
|
)
|
||||||
def after_save_supplier_price(sender, instance, created, **kwargs):
|
def after_save_supplier_price(sender, instance, created, **kwargs):
|
||||||
"""Callback function when a SupplierPriceBreak is created or updated."""
|
"""Callback function when a SupplierPriceBreak is created or updated."""
|
||||||
if (
|
from part.models import Part
|
||||||
(
|
|
||||||
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
|
if not InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING):
|
||||||
and not InvenTree.ready.isImportingData()
|
return
|
||||||
)
|
|
||||||
and instance.part
|
if InvenTree.ready.isImportingData():
|
||||||
and instance.part.part
|
return
|
||||||
):
|
|
||||||
instance.part.part.schedule_pricing_update(create=True)
|
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(
|
@receiver(
|
||||||
@@ -1062,12 +1074,24 @@ def after_save_supplier_price(sender, instance, created, **kwargs):
|
|||||||
)
|
)
|
||||||
def after_delete_supplier_price(sender, instance, **kwargs):
|
def after_delete_supplier_price(sender, instance, **kwargs):
|
||||||
"""Callback function when a SupplierPriceBreak is deleted."""
|
"""Callback function when a SupplierPriceBreak is deleted."""
|
||||||
if (
|
from part.models import Part
|
||||||
(
|
|
||||||
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
|
if not InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING):
|
||||||
and not InvenTree.ready.isImportingData()
|
return
|
||||||
)
|
|
||||||
and instance.part
|
if InvenTree.ready.isImportingData():
|
||||||
and instance.part.part
|
return
|
||||||
):
|
|
||||||
instance.part.part.schedule_pricing_update(create=False)
|
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)
|
||||||
|
|||||||
@@ -3593,23 +3593,32 @@ class StockItem(
|
|||||||
def after_delete_stock_item(sender, instance: StockItem, **kwargs):
|
def after_delete_stock_item(sender, instance: StockItem, **kwargs):
|
||||||
"""Function to be executed after a StockItem object is deleted."""
|
"""Function to be executed after a StockItem object is deleted."""
|
||||||
from part import tasks as part_tasks
|
from part import tasks as part_tasks
|
||||||
|
from part.models import Part
|
||||||
|
|
||||||
if InvenTree.ready.isImportingData():
|
if InvenTree.ready.isImportingData():
|
||||||
return
|
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):
|
if InvenTree.ready.canAppAccessDatabase(allow_test=True):
|
||||||
# Run this check in the background
|
# Run this check in the background
|
||||||
InvenTree.tasks.offload_task(
|
InvenTree.tasks.offload_task(
|
||||||
part_tasks.notify_low_stock_if_required,
|
part_tasks.notify_low_stock_if_required,
|
||||||
instance.part.pk,
|
base_part.pk,
|
||||||
group='notification',
|
group='notification',
|
||||||
force_async=True,
|
force_async=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
if InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING):
|
if InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING):
|
||||||
# Schedule an update on parent part pricing
|
# Schedule an update on parent part pricing
|
||||||
if instance.part:
|
base_part.schedule_pricing_update(create=False)
|
||||||
instance.part.schedule_pricing_update(create=False)
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=StockItem, dispatch_uid='stock_item_post_save_log')
|
@receiver(post_save, sender=StockItem, dispatch_uid='stock_item_post_save_log')
|
||||||
|
|||||||
Reference in New Issue
Block a user