2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 12:35:46 +00:00

Fix for locate item plugins (#8473)

* A hook for caching active plugins

* Add LocateItemButton

* Implement "locate" button for location detail page too

* Fix for StockApiMixin.get_serializer

- Recent refactoring removed 'path_detail' attribute

* Fix offloading of 'locate'

* Remove debug msg

* Add custom message

* Remove force_async call

* Add playwright tests
This commit is contained in:
Oliver
2024-11-13 06:49:48 +11:00
committed by GitHub
parent 7b50f3b1d3
commit 246f17113f
22 changed files with 204 additions and 27 deletions

View File

@ -6,7 +6,7 @@ from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from InvenTree.tasks import offload_task
from plugin.registry import registry
from plugin.registry import call_plugin_function, registry
from stock.models import StockItem, StockLocation
@ -59,7 +59,7 @@ class LocatePluginView(GenericAPIView):
StockItem.objects.get(pk=item_pk)
offload_task(
registry.call_plugin_function,
call_plugin_function,
plugin,
'locate_stock_item',
item_pk,
@ -78,7 +78,7 @@ class LocatePluginView(GenericAPIView):
StockLocation.objects.get(pk=location_pk)
offload_task(
registry.call_plugin_function,
call_plugin_function,
plugin,
'locate_stock_location',
location_pk,

View File

@ -159,7 +159,7 @@ class PluginsRegistry:
# Update the registry hash value
self.update_plugin_hash()
def call_plugin_function(self, slug, func, *args, **kwargs):
def call_plugin_function(self, slug: str, func: str, *args, **kwargs):
"""Call a member function (named by 'func') of the plugin named by 'slug'.
As this is intended to be run by the background worker,
@ -807,7 +807,7 @@ class PluginsRegistry:
registry: PluginsRegistry = PluginsRegistry()
def call_function(plugin_name, function_name, *args, **kwargs):
def call_plugin_function(plugin_name: str, function_name: str, *args, **kwargs):
"""Global helper function to call a specific member function of a plugin."""
return registry.call_plugin_function(plugin_name, function_name, *args, **kwargs)

View File

@ -5,7 +5,7 @@ from django.test import TestCase
from plugin import InvenTreePlugin, registry
from plugin.helpers import MixinImplementationError
from plugin.mixins import ScheduleMixin
from plugin.registry import call_function
from plugin.registry import call_plugin_function
class ExampleScheduledTaskPluginTests(TestCase):
@ -67,10 +67,10 @@ class ExampleScheduledTaskPluginTests(TestCase):
def test_calling(self):
"""Check if a function can be called without errors."""
# Check with right parameters
self.assertEqual(call_function('schedule', 'member_func'), False)
self.assertEqual(call_plugin_function('schedule', 'member_func'), False)
# Check with wrong key
self.assertEqual(call_function('does_not_exist', 'member_func'), None)
self.assertEqual(call_plugin_function('does_not_exist', 'member_func'), None)
class ScheduledTaskPluginTests(TestCase):

View File

@ -880,6 +880,7 @@ class StockApiMixin:
for key in [
'part_detail',
'path_detail',
'location_detail',
'supplier_part_detail',
'tests',