mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 03:00:54 +00:00
Error tweaks (#9891)
* Wrap model import in try/except * Fix circular imports * Adjust exception handling
This commit is contained in:
@ -38,7 +38,15 @@ def log_error(
|
|||||||
scope: The scope of the error (optional)
|
scope: The scope of the error (optional)
|
||||||
plugin: The plugin name associated with this error (optional)
|
plugin: The plugin name associated with this error (optional)
|
||||||
"""
|
"""
|
||||||
from error_report.models import Error
|
import InvenTree.ready
|
||||||
|
|
||||||
|
if any([
|
||||||
|
InvenTree.ready.isImportingData(),
|
||||||
|
InvenTree.ready.isRunningMigrations(),
|
||||||
|
InvenTree.ready.isRunningBackup(),
|
||||||
|
]):
|
||||||
|
logger.exception('Exception occurred during import, migration, or backup')
|
||||||
|
return
|
||||||
|
|
||||||
if not path:
|
if not path:
|
||||||
path = ''
|
path = ''
|
||||||
@ -78,6 +86,8 @@ def log_error(
|
|||||||
kind = kind[:128]
|
kind = kind[:128]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
from error_report.models import Error
|
||||||
|
|
||||||
Error.objects.create(kind=kind, info=info or '', data=data or '', path=path)
|
Error.objects.create(kind=kind, info=info or '', data=data or '', path=path)
|
||||||
except Exception:
|
except Exception:
|
||||||
# Not much we can do if logging the error throws a db exception
|
# Not much we can do if logging the error throws a db exception
|
||||||
|
@ -15,15 +15,12 @@ from djmoney.money import Money
|
|||||||
import common.currency
|
import common.currency
|
||||||
import common.models
|
import common.models
|
||||||
import InvenTree.helpers
|
import InvenTree.helpers
|
||||||
import part.models
|
|
||||||
import stock.models
|
import stock.models
|
||||||
|
|
||||||
logger = structlog.get_logger('inventree')
|
logger = structlog.get_logger('inventree')
|
||||||
|
|
||||||
|
|
||||||
def perform_stocktake(
|
def perform_stocktake(target, user: User, note: str = '', commit=True, **kwargs):
|
||||||
target: part.models.Part, user: User, note: str = '', commit=True, **kwargs
|
|
||||||
):
|
|
||||||
"""Perform stocktake action on a single part.
|
"""Perform stocktake action on a single part.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
@ -44,6 +41,8 @@ def perform_stocktake(
|
|||||||
|
|
||||||
In this case, the stocktake *report* will be limited to the specified location.
|
In this case, the stocktake *report* will be limited to the specified location.
|
||||||
"""
|
"""
|
||||||
|
import part.models
|
||||||
|
|
||||||
# Determine which locations are "valid" for the generated report
|
# Determine which locations are "valid" for the generated report
|
||||||
location = kwargs.get('location')
|
location = kwargs.get('location')
|
||||||
locations = location.get_descendants(include_self=True) if location else []
|
locations = location.get_descendants(include_self=True) if location else []
|
||||||
@ -162,6 +161,8 @@ def generate_stocktake_report(**kwargs):
|
|||||||
generate_report: If True, generate a stocktake report from the calculated data (default=True)
|
generate_report: If True, generate a stocktake report from the calculated data (default=True)
|
||||||
update_parts: If True, save stocktake information against each filtered Part (default = True)
|
update_parts: If True, save stocktake information against each filtered Part (default = True)
|
||||||
"""
|
"""
|
||||||
|
import part.models
|
||||||
|
|
||||||
# Determine if external locations should be excluded
|
# Determine if external locations should be excluded
|
||||||
exclude_external = kwargs.get(
|
exclude_external = kwargs.get(
|
||||||
'exclude_exernal',
|
'exclude_exernal',
|
||||||
|
Reference in New Issue
Block a user