Check before calling schedule_pricing_update (#7871)

Ref: https://github.com/inventree/InvenTree/pull/7807#issuecomment-2287770192
This commit is contained in:
Oliver 2024-08-14 14:53:52 +10:00 committed by GitHub
parent 2244f5fb27
commit 697ab1653a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 5 deletions

View File

@ -1161,6 +1161,7 @@ class SalesOrder(TotalPriceMixin, Order):
# Schedule pricing update for any referenced parts # Schedule pricing update for any referenced parts
for line in self.lines.all(): for line in self.lines.all():
if line.part:
line.part.schedule_pricing_update(create=True) line.part.schedule_pricing_update(create=True)
trigger_event('salesorder.completed', id=self.pk) trigger_event('salesorder.completed', id=self.pk)

View File

@ -4509,6 +4509,7 @@ def update_pricing_after_edit(sender, instance, created, **kwargs):
"""Callback function when a part price break is created or updated.""" """Callback function when a part price break is created or updated."""
# Update part pricing *unless* we are importing data # Update part pricing *unless* we are importing data
if InvenTree.ready.canAppAccessDatabase() and not InvenTree.ready.isImportingData(): if InvenTree.ready.canAppAccessDatabase() and not InvenTree.ready.isImportingData():
if instance.part:
instance.part.schedule_pricing_update(create=True) instance.part.schedule_pricing_update(create=True)
@ -4525,6 +4526,7 @@ def update_pricing_after_delete(sender, instance, **kwargs):
"""Callback function when a part price break is deleted.""" """Callback function when a part price break is deleted."""
# Update part pricing *unless* we are importing data # Update part pricing *unless* we are importing data
if InvenTree.ready.canAppAccessDatabase() and not InvenTree.ready.isImportingData(): if InvenTree.ready.canAppAccessDatabase() and not InvenTree.ready.isImportingData():
if instance.part:
instance.part.schedule_pricing_update(create=False) instance.part.schedule_pricing_update(create=False)

View File

@ -2293,6 +2293,7 @@ def after_delete_stock_item(sender, instance: StockItem, **kwargs):
) )
# Schedule an update on parent part pricing # Schedule an update on parent part pricing
if instance.part:
instance.part.schedule_pricing_update(create=False) instance.part.schedule_pricing_update(create=False)
@ -2312,6 +2313,7 @@ def after_save_stock_item(sender, instance: StockItem, created, **kwargs):
) )
# Schedule an update on parent part pricing # Schedule an update on parent part pricing
if instance.part:
instance.part.schedule_pricing_update(create=True) instance.part.schedule_pricing_update(create=True)