Adds plugin mixin to "locate" items

This commit is contained in:
Oliver Walters 2022-05-09 22:01:27 +10:00
parent cfaef06b9c
commit 59c747841c
2 changed files with 82 additions and 6 deletions

View File

@ -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

View File

@ -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',
]