Coverage for src/backend/InvenTree/plugin/base/locate/mixins.py: 43%
21 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
1"""Plugin mixin for locating stock items and locations."""
3import structlog
5from plugin import PluginMixinEnum
6from plugin.helpers import MixinNotImplementedError
8logger = structlog.get_logger('inventree')
11class LocateMixin:
12 """Mixin class which provides support for 'locating' inventory items, for example identifying the location of a particular StockLocation.
14 Plugins could implement audible or visual cues to direct attention to the location,
15 with (for e.g.) LED strips or buzzers, or some other method.
17 The plugins may also be used to *deliver* a particular stock item to the user.
19 A class which implements this mixin may implement the following methods:
21 - locate_stock_item : Used to locate / identify a particular stock item
22 - locate_stock_location : Used to locate / identify a particular stock location
24 Refer to the default method implementations below for more information!
25 """
27 class MixinMeta:
28 """Meta for mixin."""
30 MIXIN_NAME = 'Locate'
32 def __init__(self):
33 """Register the mixin."""
34 super().__init__()
35 self.add_mixin(PluginMixinEnum.LOCATE, True, __class__)
37 def locate_stock_item(self, item_pk):
38 """Attempt to locate a particular StockItem.
40 Arguments:
41 item_pk: The PK (primary key) of the StockItem to be located
43 The default implementation for locating a StockItem
44 attempts to locate the StockLocation where the item is located.
46 An attempt is only made if the StockItem is *in stock*
48 Note: A custom implementation could always change this behaviour
49 """
50 logger.info('LocateMixin: Attempting to locate StockItem pk=%s', item_pk)
52 from stock.models import StockItem
54 try:
55 item = StockItem.objects.get(pk=item_pk)
57 if item.in_stock and item.location is not None:
58 self.locate_stock_location(item.location.pk)
60 except StockItem.DoesNotExist: # pragma: no cover
61 logger.warning('LocateMixin: StockItem pk={item_pk} not found')
63 def locate_stock_location(self, location_pk):
64 """Attempt to location a particular StockLocation.
66 Arguments:
67 location_pk: The PK (primary key) of the StockLocation to be located
69 Note: The default implementation here does nothing!
70 """
71 raise MixinNotImplementedError