mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Small refactor for stock item post-save signals (#7449)
This commit is contained in:
parent
2d234e2831
commit
20e48e5f20
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user