Skip to content

Locate Mixin

LocateMixin

The LocateMixin class enables plugins to "locate" stock items (or stock locations) via an entirely custom method.

For example, a warehouse could be arranged with each individual 'parts bin' having an audio-visual indicator (e.g. RGB LED and buzzer). "Locating" a particular stock item causes the LED to flash and the buzzer to sound.

Another example might be a parts retrieval system, where "locating" a stock item causes the stock item to be "delivered" to the user via a conveyor.

The possibilities are endless!

Web Integration

Locate stock item from web interface Locate stock item from web interface

App Integration

If a locate plugin is installed and activated, the InvenTree mobile app displays a button for locating a StockItem or StockLocation (see below):

Locate stock item from app Locate stock item from app

Implementation

Refer to the InvenTree source code for a simple implementation example.

Sample Plugin

A simple example is provided in the InvenTree code base:

A very simple example of the 'locate' plugin.

This plugin class simply prints location information to the logger.

Source code in src/backend/InvenTree/plugin/samples/locate/locate_sample.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class SampleLocatePlugin(LocateMixin, InvenTreePlugin):
    """A very simple example of the 'locate' plugin.

    This plugin class simply prints location information to the logger.
    """

    NAME = 'SampleLocatePlugin'
    SLUG = 'samplelocate'
    TITLE = 'Sample plugin for locating items'

    VERSION = '0.2'

    def locate_stock_item(self, item_pk):
        """Locate a StockItem.

        Args:
            item_pk: primary key for item
        """
        from stock.models import StockItem

        logger.info('SampleLocatePlugin attempting to locate item ID %s', item_pk)

        try:
            item = StockItem.objects.get(pk=item_pk)
            logger.info('StockItem %s located!', item_pk)

            # Tag metadata
            item.set_metadata('located', True)

        except (ValueError, StockItem.DoesNotExist):  # pragma: no cover
            logger.exception('StockItem ID %s does not exist!', item_pk)

    def locate_stock_location(self, location_pk):
        """Locate a StockLocation.

        Args:
            location_pk: primary key for location
        """
        from stock.models import StockLocation

        logger.info(
            'SampleLocatePlugin attempting to locate location ID %s', location_pk
        )

        try:
            location = StockLocation.objects.get(pk=location_pk)
            logger.info("Location exists at '%s'", location.pathstring)

            # Tag metadata
            location.set_metadata('located', True)

        except (ValueError, StockLocation.DoesNotExist):  # pragma: no cover
            logger.exception('Location ID %s does not exist!', location_pk)