Skip to content

Commit

Permalink
Check before calling schedule_pricing_update (#7871)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat authored Aug 14, 2024
1 parent 2244f5f commit 697ab16
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/backend/InvenTree/order/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,8 @@ def _action_complete(self, *args, **kwargs):

# 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)

Expand Down
6 changes: 4 additions & 2 deletions src/backend/InvenTree/part/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4509,7 +4509,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')
Expand All @@ -4525,7 +4526,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):
Expand Down
6 changes: 4 additions & 2 deletions src/backend/InvenTree/stock/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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):
Expand Down

0 comments on commit 697ab16

Please sign in to comment.