diff --git a/InvenTree/label/api.py b/InvenTree/label/api.py index 64bea60db3..9a34a1a2a2 100644 --- a/InvenTree/label/api.py +++ b/InvenTree/label/api.py @@ -67,9 +67,7 @@ class LabelPrintMixin: plugin = registry.get_plugin(plugin_key) if plugin: - config = plugin.plugin_config() - - if config and config.active: + if plugin.is_active(): # Only return the plugin if it is enabled! return plugin else: diff --git a/InvenTree/plugin/base/event/events.py b/InvenTree/plugin/base/event/events.py index 380fc5587a..4b826d8aaa 100644 --- a/InvenTree/plugin/base/event/events.py +++ b/InvenTree/plugin/base/event/events.py @@ -58,9 +58,8 @@ def register_event(event, *args, **kwargs): if plugin.mixin_enabled('events'): - config = plugin.plugin_config() - - if config and config.active: + if plugin.is_active(): + # Only allow event registering for 'active' plugins logger.debug(f"Registering callback for plugin '{slug}'") diff --git a/InvenTree/plugin/builtin/barcodes/inventree_barcode.py b/InvenTree/plugin/builtin/barcodes/inventree_barcode.py index 90d1b68521..77382ad0e3 100644 --- a/InvenTree/plugin/builtin/barcodes/inventree_barcode.py +++ b/InvenTree/plugin/builtin/barcodes/inventree_barcode.py @@ -9,6 +9,8 @@ references model objects actually exist in the database. import json +from django.utils.translation import gettext_lazy as _ + from company.models import SupplierPart from InvenTree.helpers import hash_barcode from part.models import Part @@ -64,6 +66,8 @@ class InvenTreeInternalBarcodePlugin(InvenTreeBarcodePlugin): NAME = "InvenTreeInternalBarcode" TITLE = "Inventree Barcodes" + VERSION = "2.0" + AUTHOR = _("InvenTree contributors") def scan(self, barcode_data): """Scan a barcode against this plugin. diff --git a/InvenTree/plugin/plugin.py b/InvenTree/plugin/plugin.py index cefe59980a..806ee182a2 100644 --- a/InvenTree/plugin/plugin.py +++ b/InvenTree/plugin/plugin.py @@ -111,10 +111,10 @@ class MetaBase: if self.is_builtin: return True - cfg = self.plugin_config() + config = self.plugin_config() - if cfg: - return cfg.active + if config: + return config.active else: return False # pragma: no cover diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index d4996ad4ac..f4a60d5d4f 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -342,10 +342,7 @@ class PluginsRegistry: if plugin.mixin_enabled(mixin): if active is not None: - # Filter by 'enabled' status - config = plugin.plugin_config() - - if config.active != active: + if active != plugin.is_active(): continue result.append(plugin) @@ -402,8 +399,14 @@ class PluginsRegistry: # Append reference to plugin plg.db = plg_db - # Always activate if testing - if settings.PLUGIN_TESTING or (plg_db and plg_db.active): + # Check if this is a 'builtin' plugin + builtin = plg.check_is_builtin() + + # Determine if this plugin should be loaded: + # - If PLUGIN_TESTING is enabled + # - If this is a 'builtin' plugin + # - If this plugin has been explicitly enabled by the user + if settings.PLUGIN_TESTING or builtin or (plg_db and plg_db.active): # Check if the plugin was blocked -> threw an error; option1: package, option2: file-based if disabled and ((plg.__name__ == disabled) or (plg.__module__ == disabled)): safe_reference(plugin=plg, key=plg_key, active=False) @@ -497,10 +500,9 @@ class PluginsRegistry: for _key, plugin in plugins: if plugin.mixin_enabled('schedule'): - config = plugin.plugin_config() - # Only active tasks for plugins which are enabled - if config and config.active: + if plugin.is_active(): + # Only active tasks for plugins which are enabled plugin.register_tasks() task_keys += plugin.get_task_names()