mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-14 02:55:41 +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:
@ -13,6 +13,11 @@ def isImportingData():
|
|||||||
return 'loaddata' in sys.argv
|
return 'loaddata' in sys.argv
|
||||||
|
|
||||||
|
|
||||||
|
def isRunningMigrations():
|
||||||
|
"""Return True if the database is currently running migrations."""
|
||||||
|
return 'migrate' in sys.argv or 'makemigrations' in sys.argv
|
||||||
|
|
||||||
|
|
||||||
def canAppAccessDatabase(allow_test: bool = False, allow_plugins: bool = False, allow_shell: bool = False):
|
def canAppAccessDatabase(allow_test: bool = False, allow_plugins: bool = False, allow_shell: bool = False):
|
||||||
"""Returns True if the apps.py file can access database records.
|
"""Returns True if the apps.py file can access database records.
|
||||||
|
|
||||||
|
@ -2363,6 +2363,16 @@ class PartPricing(common.models.MetaMixin):
|
|||||||
def schedule_for_update(self, counter: int = 0):
|
def schedule_for_update(self, counter: int = 0):
|
||||||
"""Schedule this pricing to be updated"""
|
"""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():
|
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.")
|
logger.warning("Referenced part instance does not exist - skipping pricing update.")
|
||||||
return
|
return
|
||||||
@ -2415,6 +2425,14 @@ class PartPricing(common.models.MetaMixin):
|
|||||||
def update_pricing(self, counter: int = 0, cascade: bool = True):
|
def update_pricing(self, counter: int = 0, cascade: bool = True):
|
||||||
"""Recalculate all cost data for the referenced Part instance"""
|
"""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:
|
if self.pk is not None:
|
||||||
try:
|
try:
|
||||||
self.refresh_from_db()
|
self.refresh_from_db()
|
||||||
|
Reference in New Issue
Block a user