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,15 +2224,16 @@ 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
if not InvenTree.ready.isImportingData():
if not InvenTree.ready.isImportingData() and 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
)
# 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)
@receiver(post_save, sender=StockItem, dispatch_uid='stock_item_post_save_log')
@ -2240,14 +2241,18 @@ def after_save_stock_item(sender, instance: StockItem, created, **kwargs):
"""Hook function to be executed after StockItem object is saved/updated."""
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
InvenTree.tasks.offload_task(
part_tasks.notify_low_stock_if_required, instance.part
)
if InvenTree.ready.canAppAccessDatabase(allow_test=True):
instance.part.schedule_pricing_update(create=True)
# Schedule an update on parent part pricing
instance.part.schedule_pricing_update(create=True)
class StockItemAttachment(InvenTree.models.InvenTreeAttachment):