Small refactor for stock item post-save signals (#7449)

This commit is contained in:
Oliver 2024-06-16 12:36:15 +10:00 committed by GitHub
parent 2d234e2831
commit 20e48e5f20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2224,14 +2224,15 @@ 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
if not InvenTree.ready.isImportingData(): if not InvenTree.ready.isImportingData() and 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, instance.part part_tasks.notify_low_stock_if_required, instance.part
) )
# Schedule an update on parent part pricing # Schedule an update on parent part pricing
if InvenTree.ready.canAppAccessDatabase(allow_test=True):
instance.part.schedule_pricing_update(create=False) instance.part.schedule_pricing_update(create=False)
@ -2240,13 +2241,17 @@ def after_save_stock_item(sender, instance: StockItem, created, **kwargs):
"""Hook function to be executed after StockItem object is saved/updated.""" """Hook function to be executed after StockItem object is saved/updated."""
from part import tasks as part_tasks from part import tasks as part_tasks
if created and not InvenTree.ready.isImportingData(): if (
created
and not InvenTree.ready.isImportingData()
and 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, instance.part part_tasks.notify_low_stock_if_required, instance.part
) )
if InvenTree.ready.canAppAccessDatabase(allow_test=True): # Schedule an update on parent part pricing
instance.part.schedule_pricing_update(create=True) instance.part.schedule_pricing_update(create=True)