From 36ecd41695a33537f21ad2ea732cf19c728c867a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 14 Aug 2024 15:10:14 +1000 Subject: [PATCH] Check before calling schedule_pricing_update (#7871) (#7872) Ref: https://github.com/inventree/InvenTree/pull/7807#issuecomment-2287770192 (cherry picked from commit 697ab1653ac6d1566805dc4bdc911199ba1ee286) Co-authored-by: Oliver --- src/backend/InvenTree/order/models.py | 3 ++- src/backend/InvenTree/part/models.py | 6 ++++-- src/backend/InvenTree/stock/models.py | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/backend/InvenTree/order/models.py b/src/backend/InvenTree/order/models.py index 2362c01ee4..f71c6af52e 100644 --- a/src/backend/InvenTree/order/models.py +++ b/src/backend/InvenTree/order/models.py @@ -1105,7 +1105,8 @@ class SalesOrder(TotalPriceMixin, Order): # Schedule pricing update for any referenced parts for line in self.lines.all(): - line.part.schedule_pricing_update(create=True) + if line.part: + line.part.schedule_pricing_update(create=True) trigger_event('salesorder.completed', id=self.pk) diff --git a/src/backend/InvenTree/part/models.py b/src/backend/InvenTree/part/models.py index 20d28b9f47..519b793216 100644 --- a/src/backend/InvenTree/part/models.py +++ b/src/backend/InvenTree/part/models.py @@ -4510,7 +4510,8 @@ def update_pricing_after_edit(sender, instance, created, **kwargs): """Callback function when a part price break is created or updated.""" # Update part pricing *unless* we are importing data if InvenTree.ready.canAppAccessDatabase() and not InvenTree.ready.isImportingData(): - instance.part.schedule_pricing_update(create=True) + if instance.part: + instance.part.schedule_pricing_update(create=True) @receiver(post_delete, sender=BomItem, dispatch_uid='post_delete_bom_item') @@ -4526,7 +4527,8 @@ def update_pricing_after_delete(sender, instance, **kwargs): """Callback function when a part price break is deleted.""" # Update part pricing *unless* we are importing data if InvenTree.ready.canAppAccessDatabase() and not InvenTree.ready.isImportingData(): - instance.part.schedule_pricing_update(create=False) + if instance.part: + instance.part.schedule_pricing_update(create=False) class BomItemSubstitute(InvenTree.models.InvenTreeMetadataModel): diff --git a/src/backend/InvenTree/stock/models.py b/src/backend/InvenTree/stock/models.py index 35ce61a99a..a3ee17a7ea 100644 --- a/src/backend/InvenTree/stock/models.py +++ b/src/backend/InvenTree/stock/models.py @@ -2293,7 +2293,8 @@ def after_delete_stock_item(sender, instance: StockItem, **kwargs): ) # Schedule an update on parent part pricing - instance.part.schedule_pricing_update(create=False) + if instance.part: + instance.part.schedule_pricing_update(create=False) @receiver(post_save, sender=StockItem, dispatch_uid='stock_item_post_save_log') @@ -2312,7 +2313,8 @@ def after_save_stock_item(sender, instance: StockItem, created, **kwargs): ) # Schedule an update on parent part pricing - instance.part.schedule_pricing_update(create=True) + if instance.part: + instance.part.schedule_pricing_update(create=True) class StockItemTracking(InvenTree.models.InvenTreeModel):