diff --git a/src/backend/InvenTree/plugin/installer.py b/src/backend/InvenTree/plugin/installer.py index 3720e02ad1..f1b84eeffe 100644 --- a/src/backend/InvenTree/plugin/installer.py +++ b/src/backend/InvenTree/plugin/installer.py @@ -337,7 +337,7 @@ def uninstall_plugin(cfg: plugin.models.PluginConfig, user=None, delete_config=T cfg.delete() # Remove static files associated with this plugin - plugin.staticfiles.clear_static_dir(f'plugins/{cfg.key}/', recursive=True) + plugin.staticfiles.clear_plugin_static_files(cfg.key) # Reload the plugin registry registry.reload_plugins(full_reload=True, force_reload=True, collect=True) diff --git a/src/backend/InvenTree/plugin/models.py b/src/backend/InvenTree/plugin/models.py index 4989f56af2..6f679c213b 100644 --- a/src/backend/InvenTree/plugin/models.py +++ b/src/backend/InvenTree/plugin/models.py @@ -154,6 +154,14 @@ class PluginConfig(InvenTree.models.MetadataMixin, models.Model): warnings.warn('A reload was triggered', stacklevel=2) registry.reload_plugins() + # Update static files for this plugin + if self.active: + plugin.staticfiles.copy_plugin_static_files( + self.key, check_reload=False + ) + else: + plugin.staticfiles.clear_plugin_static_files(self.key) + @admin.display(boolean=True, description=_('Installed')) def is_installed(self) -> bool: """Simple check to determine if this plugin is installed. diff --git a/src/backend/InvenTree/plugin/staticfiles.py b/src/backend/InvenTree/plugin/staticfiles.py index fa4fba4ba1..834f426dc6 100644 --- a/src/backend/InvenTree/plugin/staticfiles.py +++ b/src/backend/InvenTree/plugin/staticfiles.py @@ -115,3 +115,8 @@ def copy_plugin_static_files(slug, check_reload=True): copied += 1 logger.info("Copied %s static files for plugin '%s'.", copied, slug) + + +def clear_plugin_static_files(slug: str, recursive: bool = True): + """Clear static files for the specified plugin.""" + clear_static_dir(f'plugins/{slug}/', recursive=recursive)