diff --git a/InvenTree/plugin/builtin/integration/mixins.py b/InvenTree/plugin/builtin/integration/mixins.py index b22efc9415..7a7c9c4404 100644 --- a/InvenTree/plugin/builtin/integration/mixins.py +++ b/InvenTree/plugin/builtin/integration/mixins.py @@ -432,6 +432,70 @@ class LabelPrintingMixin: ... # pragma: no cover +class LocateMixin: + """ + Mixin class which provides support for 'locating' inventory items, + for example identifying the location of a particular StockLocation. + + Plugins could implement audible or visual cues to direct attention to the location, + with (for e.g.) LED strips or buzzers, or some other method. + + The plugins may also be used to *deliver* a particular stock item to the user. + + A class which implements this mixin may implement the following methods: + + - locate_stock_item : Used to locate / identify a particular stock item + - locate_stock_location : Used to locate / identify a particular stock location + + Refer to the default method implementations below for more information! + + """ + + class MixinMeta: + MIXIN_NAME = "Locate" + + def __init__(self): + super().__init__() + self.add_mixin('localte', True, __class__) + + def locate_stock_item(self, item_pk): + """ + Attempt to locate a particular StockItem + + Arguments: + item_pk: The PK (primary key) of the StockItem to be located + + The default implementation for locating a StockItem + attempts to locate the StockLocation where the item is located. + + An attempt is only made if the StockItem is *in stock* + + Note: A custom implemenation could always change this behaviour + """ + + from stock.models import StockItem + + try: + item = StockItem.objects.get(pk=item_pk) + + if item.in_stock and item.location is not None: + self.locate_stock_location(item.location.pk) + + except StockItem.DoesNotExist: + pass + + def locate_stock_location(self, location_pk): + """ + Attempt to location a particular StockLocation + + Arguments: + location_pk: The PK (primary key) of the StockLocation to be located + + Note: The default implementation here does nothing! + """ + ... + + class APICallMixin: """ Mixin that enables easier API calls for a plugin diff --git a/InvenTree/plugin/mixins/__init__.py b/InvenTree/plugin/mixins/__init__.py index fdbe863e19..bf44e29897 100644 --- a/InvenTree/plugin/mixins/__init__.py +++ b/InvenTree/plugin/mixins/__init__.py @@ -2,7 +2,18 @@ Utility class to enable simpler imports """ -from ..builtin.integration.mixins import APICallMixin, AppMixin, LabelPrintingMixin, SettingsMixin, EventMixin, ScheduleMixin, UrlsMixin, NavigationMixin, PanelMixin +from ..builtin.integration.mixins import ( + APICallMixin, + AppMixin, + EventMixin, + LabelPrintingMixin, + LocateMixin, + NavigationMixin, + PanelMixin, + ScheduleMixin, + SettingsMixin, + UrlsMixin, +) from common.notifications import SingleNotificationMethod, BulkNotificationMethod @@ -10,17 +21,18 @@ from ..builtin.action.mixins import ActionMixin from ..builtin.barcode.mixins import BarcodeMixin __all__ = [ + 'ActionMixin', 'APICallMixin', 'AppMixin', + 'BarcodeMixin', + 'BulkNotificationMethod', 'EventMixin', 'LabelPrintingMixin', + 'LocateMixin', + 'PanelMixin', 'NavigationMixin', 'ScheduleMixin', 'SettingsMixin', - 'UrlsMixin', - 'PanelMixin', - 'ActionMixin', - 'BarcodeMixin', 'SingleNotificationMethod', - 'BulkNotificationMethod', + 'UrlsMixin', ]