diff --git a/InvenTree/InvenTree/tasks.py b/InvenTree/InvenTree/tasks.py index 8af30264d3..cb52245740 100644 --- a/InvenTree/InvenTree/tasks.py +++ b/InvenTree/InvenTree/tasks.py @@ -11,6 +11,7 @@ from django.utils import timezone from django.core.exceptions import AppRegistryNotReady from django.db.utils import OperationalError, ProgrammingError +from django.core import mail as django_mail logger = logging.getLogger("inventree") @@ -292,7 +293,7 @@ def send_email(subject, body, recipients, from_email=None, html_message=None): recipients = [recipients] offload_task( - 'django.core.mail.send_mail', + django_mail.send_mail, subject, body, from_email, diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 6291b321a8..f15452c697 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -797,13 +797,9 @@ class CurrencyRefreshView(RedirectView): On a POST request we will attempt to refresh the exchange rates """ - from InvenTree.tasks import offload_task + from InvenTree.tasks import offload_task, update_exchange_rates - # Define associated task from InvenTree.tasks list of methods - taskname = 'InvenTree.tasks.update_exchange_rates' - - # Run it - offload_task(taskname, force_sync=True) + offload_task(update_exchange_rates, force_sync=True) return redirect(reverse_lazy('settings')) diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index a1517d73dd..e7a1bbd1b3 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -41,6 +41,7 @@ from plugin.events import trigger_event from part import models as PartModels from stock import models as StockModels from users import models as UserModels +from . import tasks as build_tasks def get_next_build_number(): @@ -1146,7 +1147,7 @@ def after_save_build(sender, instance: Build, created: bool, **kwargs): # A new Build has just been created # Run checks on required parts - InvenTree.tasks.offload_task('build.tasks.check_build_stock', instance) + InvenTree.tasks.offload_task(build_tasks.check_build_stock, instance) class BuildOrderAttachment(InvenTreeAttachment): diff --git a/InvenTree/common/test_tasks.py b/InvenTree/common/test_tasks.py index 3f85316c41..c28a1d19fe 100644 --- a/InvenTree/common/test_tasks.py +++ b/InvenTree/common/test_tasks.py @@ -2,6 +2,7 @@ from django.test import TestCase from common.models import NotificationEntry +from . import tasks as common_tasks from InvenTree.tasks import offload_task @@ -14,4 +15,4 @@ class TaskTest(TestCase): # check empty run self.assertEqual(NotificationEntry.objects.all().count(), 0) - offload_task('common.tasks.delete_old_notifications',) + offload_task(common_tasks.delete_old_notifications,) diff --git a/InvenTree/label/api.py b/InvenTree/label/api.py index cb4b939157..34ced6a3cd 100644 --- a/InvenTree/label/api.py +++ b/InvenTree/label/api.py @@ -24,6 +24,7 @@ from plugin.registry import registry from stock.models import StockItem, StockLocation from part.models import Part +from plugin.base.label import label as plugin_label from .models import StockItemLabel, StockLocationLabel, PartLabel from .serializers import StockItemLabelSerializer, StockLocationLabelSerializer, PartLabelSerializer @@ -156,7 +157,7 @@ class LabelPrintMixin: # Offload a background task to print the provided label offload_task( - 'plugin.base.label.label.print_label', + plugin_label.print_label, plugin.plugin_slug(), image, label_instance=label_instance, diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 96ffa581f4..229b25bf16 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -63,6 +63,7 @@ from stock import models as StockModels import common.models import part.settings as part_settings +from part import tasks as part_tasks logger = logging.getLogger("inventree") @@ -2298,7 +2299,7 @@ def after_save_part(sender, instance: Part, created, **kwargs): # Check part stock only if we are *updating* the part (not creating it) # Run this check in the background - InvenTree.tasks.offload_task('part.tasks.notify_low_stock_if_required', instance) + InvenTree.tasks.offload_task(part_tasks.notify_low_stock_if_required, instance) class PartAttachment(InvenTreeAttachment): diff --git a/InvenTree/part/tasks.py b/InvenTree/part/tasks.py index b158d26ad3..c8615bd4a2 100644 --- a/InvenTree/part/tasks.py +++ b/InvenTree/part/tasks.py @@ -10,6 +10,7 @@ import InvenTree.tasks import common.notifications import part.models +from part import tasks as part_tasks logger = logging.getLogger("inventree") @@ -49,6 +50,6 @@ def notify_low_stock_if_required(part: part.models.Part): for p in parts: if p.is_part_low_on_stock(): InvenTree.tasks.offload_task( - 'part.tasks.notify_low_stock', + part_tasks.notify_low_stock, p ) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index a46d43b007..69be97cf4b 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -49,6 +49,7 @@ from users.models import Owner from company import models as CompanyModels from part import models as PartModels +from part import tasks as part_tasks class StockLocation(InvenTreeTree): @@ -2026,7 +2027,7 @@ def after_delete_stock_item(sender, instance: StockItem, **kwargs): if not InvenTree.ready.isImportingData(): # Run this check in the background - InvenTree.tasks.offload_task('part.tasks.notify_low_stock_if_required', instance.part) + InvenTree.tasks.offload_task(part_tasks.notify_low_stock_if_required, instance.part) @receiver(post_save, sender=StockItem, dispatch_uid='stock_item_post_save_log') @@ -2037,7 +2038,7 @@ def after_save_stock_item(sender, instance: StockItem, created, **kwargs): if not InvenTree.ready.isImportingData(): # Run this check in the background - InvenTree.tasks.offload_task('part.tasks.notify_low_stock_if_required', instance.part) + InvenTree.tasks.offload_task(part_tasks.notify_low_stock_if_required, instance.part) class StockItemAttachment(InvenTreeAttachment):