mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 20:15:44 +00:00
Fixes for circlular imports
This commit is contained in:
@ -7,6 +7,7 @@ import re
|
|||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
from django.http.response import StreamingHttpResponse
|
from django.http.response import StreamingHttpResponse
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
from djmoney.contrib.exchange.models import ExchangeBackend, Rate
|
from djmoney.contrib.exchange.models import ExchangeBackend, Rate
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
@ -337,3 +338,8 @@ class InvenTreeAPITestCase(ExchangeRateMixin, UserMixin, APITestCase):
|
|||||||
data.append(entry)
|
data.append(entry)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
class InvenTreeTestCase(ExchangeRateMixin, UserMixin, TestCase):
|
||||||
|
"""Testcase with user setup buildin."""
|
||||||
|
pass
|
||||||
|
@ -6,7 +6,7 @@ Only used for testing the js files! - This file is omited from coverage.
|
|||||||
import os # pragma: no cover
|
import os # pragma: no cover
|
||||||
import pathlib # pragma: no cover
|
import pathlib # pragma: no cover
|
||||||
|
|
||||||
from InvenTree.helpers import InvenTreeTestCase # pragma: no cover
|
from InvenTree.api_tester import InvenTreeTestCase # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
class RenderJavascriptFiles(InvenTreeTestCase): # pragma: no cover
|
class RenderJavascriptFiles(InvenTreeTestCase): # pragma: no cover
|
||||||
|
@ -19,7 +19,6 @@ from django.core.files.storage import default_storage
|
|||||||
from django.core.validators import URLValidator
|
from django.core.validators import URLValidator
|
||||||
from django.db.utils import OperationalError, ProgrammingError
|
from django.db.utils import OperationalError, ProgrammingError
|
||||||
from django.http import StreamingHttpResponse
|
from django.http import StreamingHttpResponse
|
||||||
from django.test import TestCase
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
import moneyed.localization
|
import moneyed.localization
|
||||||
@ -31,13 +30,8 @@ from djmoney.money import Money
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
import common.models
|
import common.models
|
||||||
|
import common.settings
|
||||||
import InvenTree.version
|
import InvenTree.version
|
||||||
from common.notifications import (InvenTreeNotificationBodies,
|
|
||||||
NotificationBody, trigger_notification)
|
|
||||||
from common.settings import currency_code_default
|
|
||||||
|
|
||||||
from .api_tester import ExchangeRateMixin, UserMixin
|
|
||||||
from .settings import MEDIA_URL, STATIC_URL
|
|
||||||
|
|
||||||
logger = logging.getLogger('inventree')
|
logger = logging.getLogger('inventree')
|
||||||
|
|
||||||
@ -81,12 +75,12 @@ def constructPathString(path, max_chars=250):
|
|||||||
|
|
||||||
def getMediaUrl(filename):
|
def getMediaUrl(filename):
|
||||||
"""Return the qualified access path for the given file, under the media directory."""
|
"""Return the qualified access path for the given file, under the media directory."""
|
||||||
return os.path.join(MEDIA_URL, str(filename))
|
return os.path.join(settings.MEDIA_URL, str(filename))
|
||||||
|
|
||||||
|
|
||||||
def getStaticUrl(filename):
|
def getStaticUrl(filename):
|
||||||
"""Return the qualified access path for the given file, under the static media directory."""
|
"""Return the qualified access path for the given file, under the static media directory."""
|
||||||
return os.path.join(STATIC_URL, str(filename))
|
return os.path.join(settings.STATIC_URL, str(filename))
|
||||||
|
|
||||||
|
|
||||||
def construct_absolute_url(*arg, **kwargs):
|
def construct_absolute_url(*arg, **kwargs):
|
||||||
@ -470,7 +464,7 @@ def decimal2money(d, currency=None):
|
|||||||
A Money object from the input(s)
|
A Money object from the input(s)
|
||||||
"""
|
"""
|
||||||
if not currency:
|
if not currency:
|
||||||
currency = currency_code_default()
|
currency = common.settings.currency_code_default()
|
||||||
return Money(d, currency)
|
return Money(d, currency)
|
||||||
|
|
||||||
|
|
||||||
@ -1091,12 +1085,7 @@ def inheritors(cls):
|
|||||||
return subcls
|
return subcls
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeTestCase(ExchangeRateMixin, UserMixin, TestCase):
|
def notify_responsible(instance, sender, content=None, exclude=None):
|
||||||
"""Testcase with user setup buildin."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def notify_responsible(instance, sender, content: NotificationBody = InvenTreeNotificationBodies.NewOrder, exclude=None):
|
|
||||||
"""Notify all responsible parties of a change in an instance.
|
"""Notify all responsible parties of a change in an instance.
|
||||||
|
|
||||||
Parses the supplied content with the provided instance and sender and sends a notification to all responsible users,
|
Parses the supplied content with the provided instance and sender and sends a notification to all responsible users,
|
||||||
@ -1108,6 +1097,12 @@ def notify_responsible(instance, sender, content: NotificationBody = InvenTreeNo
|
|||||||
content (NotificationBody, optional): _description_. Defaults to InvenTreeNotificationBodies.NewOrder.
|
content (NotificationBody, optional): _description_. Defaults to InvenTreeNotificationBodies.NewOrder.
|
||||||
exclude (User, optional): User instance that should be excluded. Defaults to None.
|
exclude (User, optional): User instance that should be excluded. Defaults to None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import common.notifications
|
||||||
|
|
||||||
|
if content is None:
|
||||||
|
content = common.notifications.InvenTreeNotificationBodies.NewOrder
|
||||||
|
|
||||||
if instance.responsible is not None:
|
if instance.responsible is not None:
|
||||||
# Setup context for notification parsing
|
# Setup context for notification parsing
|
||||||
content_context = {
|
content_context = {
|
||||||
@ -1130,7 +1125,7 @@ def notify_responsible(instance, sender, content: NotificationBody = InvenTreeNo
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Create notification
|
# Create notification
|
||||||
trigger_notification(
|
common.notifications.trigger_notification(
|
||||||
instance,
|
instance,
|
||||||
content.slug.format(**content_context),
|
content.slug.format(**content_context),
|
||||||
targets=[instance.responsible],
|
targets=[instance.responsible],
|
||||||
|
@ -6,8 +6,7 @@ from django.urls import reverse
|
|||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
|
||||||
from InvenTree.api_tester import InvenTreeAPITestCase
|
from InvenTree.api_tester import InvenTreeAPITestCase, InvenTreeTestCase
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
|
||||||
from users.models import RuleSet, update_group_roles
|
from users.models import RuleSet, update_group_roles
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ from django.urls import reverse
|
|||||||
|
|
||||||
from error_report.models import Error
|
from error_report.models import Error
|
||||||
|
|
||||||
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
from InvenTree.exceptions import log_error
|
from InvenTree.exceptions import log_error
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
|
||||||
|
|
||||||
|
|
||||||
class MiddlewareTests(InvenTreeTestCase):
|
class MiddlewareTests(InvenTreeTestCase):
|
||||||
|
@ -5,7 +5,7 @@ import os
|
|||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
|
|
||||||
|
|
||||||
class ViewTests(InvenTreeTestCase):
|
class ViewTests(InvenTreeTestCase):
|
||||||
|
@ -25,6 +25,7 @@ from InvenTree.status_codes import BuildStatus, StockStatus, StockHistoryCode
|
|||||||
|
|
||||||
from build.validators import generate_next_build_reference, validate_build_order_reference
|
from build.validators import generate_next_build_reference, validate_build_order_reference
|
||||||
|
|
||||||
|
import common.models
|
||||||
import InvenTree.fields
|
import InvenTree.fields
|
||||||
import InvenTree.helpers
|
import InvenTree.helpers
|
||||||
import InvenTree.models
|
import InvenTree.models
|
||||||
@ -299,7 +300,7 @@ class Build(MPTTModel, InvenTree.models.InvenTreeBarcodeMixin, InvenTree.models.
|
|||||||
)
|
)
|
||||||
|
|
||||||
project_code = models.ForeignKey(
|
project_code = models.ForeignKey(
|
||||||
'common.ProjectCode',
|
common.models.ProjectCode,
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
blank=True, null=True,
|
blank=True, null=True,
|
||||||
verbose_name=_('Project Code'),
|
verbose_name=_('Project Code'),
|
||||||
|
@ -4,7 +4,7 @@ from django.urls import reverse
|
|||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
|
|
||||||
from .models import Build
|
from .models import Build
|
||||||
from stock.models import StockItem
|
from stock.models import StockItem
|
||||||
|
@ -8,12 +8,12 @@ from django.contrib.auth import get_user_model
|
|||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
import common.models
|
||||||
import InvenTree.helpers
|
import InvenTree.helpers
|
||||||
from common.models import NotificationEntry, NotificationMessage
|
import plugin.models
|
||||||
|
import users.models
|
||||||
from InvenTree.ready import isImportingData
|
from InvenTree.ready import isImportingData
|
||||||
from plugin import registry
|
from plugin import registry
|
||||||
from plugin.models import NotificationUserSetting, PluginConfig
|
|
||||||
from users.models import Owner
|
|
||||||
|
|
||||||
logger = logging.getLogger('inventree')
|
logger = logging.getLogger('inventree')
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ class NotificationMethod:
|
|||||||
|
|
||||||
def usersetting(self, target):
|
def usersetting(self, target):
|
||||||
"""Returns setting for this method for a given user."""
|
"""Returns setting for this method for a given user."""
|
||||||
return NotificationUserSetting.get_setting(f'NOTIFICATION_METHOD_{self.METHOD_NAME.upper()}', user=target, method=self.METHOD_NAME)
|
return plugin.models.NotificationUserSetting.get_setting(f'NOTIFICATION_METHOD_{self.METHOD_NAME.upper()}', user=target, method=self.METHOD_NAME)
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ class MethodStorageClass:
|
|||||||
|
|
||||||
# make sure the setting exists
|
# make sure the setting exists
|
||||||
self.user_settings[new_key] = item.USER_SETTING
|
self.user_settings[new_key] = item.USER_SETTING
|
||||||
NotificationUserSetting.get_setting(
|
plugin.models.NotificationUserSetting.get_setting(
|
||||||
key=new_key,
|
key=new_key,
|
||||||
user=user,
|
user=user,
|
||||||
method=item.METHOD_NAME,
|
method=item.METHOD_NAME,
|
||||||
@ -247,7 +247,7 @@ class UIMessageNotification(SingleNotificationMethod):
|
|||||||
|
|
||||||
def send(self, target):
|
def send(self, target):
|
||||||
"""Send a UI notification to a user."""
|
"""Send a UI notification to a user."""
|
||||||
NotificationMessage.objects.create(
|
common.models.NotificationMessage.objects.create(
|
||||||
target_object=self.obj,
|
target_object=self.obj,
|
||||||
source_object=target,
|
source_object=target,
|
||||||
user=target,
|
user=target,
|
||||||
@ -338,7 +338,7 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
|
|||||||
# Check if we have notified recently...
|
# Check if we have notified recently...
|
||||||
delta = timedelta(days=1)
|
delta = timedelta(days=1)
|
||||||
|
|
||||||
if NotificationEntry.check_recent(category, obj_ref_value, delta):
|
if common.models.NotificationEntry.check_recent(category, obj_ref_value, delta):
|
||||||
logger.info(f"Notification '{category}' has recently been sent for '{str(obj)}' - SKIPPING")
|
logger.info(f"Notification '{category}' has recently been sent for '{str(obj)}' - SKIPPING")
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -369,7 +369,7 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
|
|||||||
if user not in target_exclude:
|
if user not in target_exclude:
|
||||||
target_users.add(user)
|
target_users.add(user)
|
||||||
# Owner instance (either 'user' or 'group' is provided)
|
# Owner instance (either 'user' or 'group' is provided)
|
||||||
elif isinstance(target, Owner):
|
elif isinstance(target, users.models.Owner):
|
||||||
for owner in target.get_related_owners(include_group=False):
|
for owner in target.get_related_owners(include_group=False):
|
||||||
user = owner.owner
|
user = owner.owner
|
||||||
if user not in target_exclude:
|
if user not in target_exclude:
|
||||||
@ -398,12 +398,12 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
|
|||||||
logger.error(error)
|
logger.error(error)
|
||||||
|
|
||||||
# Set delivery flag
|
# Set delivery flag
|
||||||
NotificationEntry.notify(category, obj_ref_value)
|
common.models.NotificationEntry.notify(category, obj_ref_value)
|
||||||
else:
|
else:
|
||||||
logger.info(f"No possible users for notification '{category}'")
|
logger.info(f"No possible users for notification '{category}'")
|
||||||
|
|
||||||
|
|
||||||
def trigger_superuser_notification(plugin: PluginConfig, msg: str):
|
def trigger_superuser_notification(plugin: plugin.models.PluginConfig, msg: str):
|
||||||
"""Trigger a notification to all superusers.
|
"""Trigger a notification to all superusers.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -14,8 +14,8 @@ from django.urls import reverse
|
|||||||
|
|
||||||
import PIL
|
import PIL
|
||||||
|
|
||||||
from InvenTree.api_tester import InvenTreeAPITestCase, PluginMixin
|
from InvenTree.api_tester import (InvenTreeAPITestCase, InvenTreeTestCase,
|
||||||
from InvenTree.helpers import InvenTreeTestCase, str2bool
|
PluginMixin, str2bool)
|
||||||
from plugin import registry
|
from plugin import registry
|
||||||
from plugin.models import NotificationUserSetting
|
from plugin.models import NotificationUserSetting
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
|
|
||||||
|
|
||||||
class CompanyViewTest(InvenTreeTestCase):
|
class CompanyViewTest(InvenTreeTestCase):
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
|
|
||||||
|
|
||||||
class OrderViewTestCase(InvenTreeTestCase):
|
class OrderViewTestCase(InvenTreeTestCase):
|
||||||
|
@ -4,7 +4,7 @@ import csv
|
|||||||
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
|
|
||||||
|
|
||||||
class BomExportTest(InvenTreeTestCase):
|
class BomExportTest(InvenTreeTestCase):
|
||||||
|
@ -14,7 +14,7 @@ from common.models import (InvenTreeSetting, InvenTreeUserSetting,
|
|||||||
NotificationEntry, NotificationMessage)
|
NotificationEntry, NotificationMessage)
|
||||||
from common.notifications import UIMessageNotification, storage
|
from common.notifications import UIMessageNotification, storage
|
||||||
from InvenTree import version
|
from InvenTree import version
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
|
|
||||||
from .models import (Part, PartCategory, PartCategoryStar, PartRelated,
|
from .models import (Part, PartCategory, PartCategoryStar, PartRelated,
|
||||||
PartStar, PartStocktake, PartTestTemplate,
|
PartStar, PartStocktake, PartTestTemplate,
|
||||||
|
@ -10,7 +10,7 @@ import company.models
|
|||||||
import order.models
|
import order.models
|
||||||
import part.models
|
import part.models
|
||||||
import stock.models
|
import stock.models
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
from InvenTree.status_codes import PurchaseOrderStatus
|
from InvenTree.status_codes import PurchaseOrderStatus
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
|
|
||||||
from .models import Part
|
from .models import Part
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
from plugin import InvenTreePlugin
|
from plugin import InvenTreePlugin
|
||||||
from plugin.mixins import ActionMixin
|
from plugin.mixins import ActionMixin
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ from django.urls import include, re_path, reverse
|
|||||||
|
|
||||||
from error_report.models import Error
|
from error_report.models import Error
|
||||||
|
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
from plugin import InvenTreePlugin
|
from plugin import InvenTreePlugin
|
||||||
from plugin.base.integration.mixins import PanelMixin
|
from plugin.base.integration.mixins import PanelMixin
|
||||||
from plugin.helpers import MixinNotImplementedError
|
from plugin.helpers import MixinNotImplementedError
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Unit tests for action plugins."""
|
"""Unit tests for action plugins."""
|
||||||
|
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
|
|
||||||
|
|
||||||
class SampleIntegrationPluginTests(InvenTreeTestCase):
|
class SampleIntegrationPluginTests(InvenTreeTestCase):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Unit tests for action plugins."""
|
"""Unit tests for action plugins."""
|
||||||
|
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
from plugin.samples.integration.simpleactionplugin import SimpleActionPlugin
|
from plugin.samples.integration.simpleactionplugin import SimpleActionPlugin
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ from django.contrib.auth.models import Group
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from common.models import InvenTreeSetting
|
from common.models import InvenTreeSetting
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
from InvenTree.status_codes import StockStatus
|
from InvenTree.status_codes import StockStatus
|
||||||
from stock.models import StockItem, StockLocation
|
from stock.models import StockItem, StockLocation
|
||||||
from users.models import Owner
|
from users.models import Owner
|
||||||
|
@ -9,7 +9,7 @@ from django.test import override_settings
|
|||||||
from build.models import Build
|
from build.models import Build
|
||||||
from common.models import InvenTreeSetting
|
from common.models import InvenTreeSetting
|
||||||
from company.models import Company
|
from company.models import Company
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
from InvenTree.status_codes import StockHistoryCode
|
from InvenTree.status_codes import StockHistoryCode
|
||||||
from order.models import SalesOrder
|
from order.models import SalesOrder
|
||||||
from part.models import Part
|
from part.models import Part
|
||||||
|
@ -7,7 +7,7 @@ from django.urls import reverse
|
|||||||
|
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
|
|
||||||
from InvenTree.helpers import InvenTreeTestCase
|
from InvenTree.api_tester import InvenTreeTestCase
|
||||||
from users.models import Owner, RuleSet
|
from users.models import Owner, RuleSet
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user