From 172705cc3bb55ee31cb3be509cf70f20ad245240 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 9 May 2022 22:13:07 +1000 Subject: [PATCH] Adds sample plugin for locating items --- .../plugin/samples/integration/locate.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 InvenTree/plugin/samples/integration/locate.py diff --git a/InvenTree/plugin/samples/integration/locate.py b/InvenTree/plugin/samples/integration/locate.py new file mode 100644 index 0000000000..37645da771 --- /dev/null +++ b/InvenTree/plugin/samples/integration/locate.py @@ -0,0 +1,34 @@ +""" +Sample plugin for locating stock items / locations. + +Note: This plugin does not *actually* locate anything! +""" + +import logging + +from plugin import IntegrationPluginBase +from plugin.mixins import LocateMixin + + +logger = logging.getLogger('inventree') + + +class SampleLocatePlugin(LocateMixin, IntegrationPluginBase): + + PLUGIN_NAME = "SampleLocatePlugin" + PLUGIN_SLUG = "samplelocate", + PLUGIN_TITLE = "Sample plugin for locating items" + + VERSION = "0.1" + + def locate_stock_location(self, location_pk): + + from stock.models import StockLocation + + logger.info(f"SampleLocatePlugin attempting to locate location ID {location_pk}") + + try: + location = StockLocation.objects.get(pk=location_pk) + logger.info(f"Location exists at '{location.pathstring}'") + except StockLocation.DoesNotExist: + logger.error(f"Location ID {location_pk} does not exist!")