2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 04:55:44 +00:00

Skip pricing updates when importing data (#5026)

* Skip pricing updates when importing data

- Depending on migration state, pricing table might not exist
- post-save hooks can call update_pricing
- So, ignore if running data migration or import

* Typo fix
This commit is contained in:
Oliver
2023-06-13 12:40:21 +10:00
committed by GitHub
parent 9117c2234b
commit 98bddd32d0
2 changed files with 23 additions and 0 deletions

View File

@ -2363,6 +2363,16 @@ class PartPricing(common.models.MetaMixin):
def schedule_for_update(self, counter: int = 0):
"""Schedule this pricing to be updated"""
import InvenTree.ready
# If importing data, skip pricing update
if InvenTree.ready.isImportingData():
return
# If running data migrations, skip pricing update
if InvenTree.ready.isRunningMigrations():
return
if not self.part or not self.part.pk or not Part.objects.filter(pk=self.part.pk).exists():
logger.warning("Referenced part instance does not exist - skipping pricing update.")
return
@ -2415,6 +2425,14 @@ class PartPricing(common.models.MetaMixin):
def update_pricing(self, counter: int = 0, cascade: bool = True):
"""Recalculate all cost data for the referenced Part instance"""
# If importing data, skip pricing update
if InvenTree.ready.isImportingData():
return
# If running data migrations, skip pricing update
if InvenTree.ready.isRunningMigrations():
return
if self.pk is not None:
try:
self.refresh_from_db()