diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index c1fee741da..f86a61e80d 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -46,11 +46,13 @@ def WrapWithQuotes(text, quote='"'): return text -def MakeBarcode(object_type, data={}): +def MakeBarcode(object_type, object_url, data={}): """ Generate a string for a barcode. Adds some global InvenTree parameters. Args: - data: Python dict obejct which will be rendered to string (must only contain stringable values) + object_type: string describing the object type e.g. 'StockItem' + object_url: url for JSON API detail view of the object + data: Python dict object containing extra datawhich will be rendered to string (must only contain stringable values) Returns: json string of the supplied data plus some other data @@ -58,6 +60,7 @@ def MakeBarcode(object_type, data={}): # Add in some generic InvenTree data data['type'] = object_type + data['url'] = object_url data['tool'] = 'InvenTree' data['generated'] = str(datetime.now().date()) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index a145309cec..2690207f05 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -345,11 +345,11 @@ class LocationDetail(generics.RetrieveUpdateDestroyAPIView): stock_endpoints = [ - url(r'^$', StockDetail.as_view(), name='stockitem-detail'), + url(r'^$', StockDetail.as_view(), name='api-stock-detail'), ] location_endpoints = [ - url(r'^$', LocationDetail.as_view(), name='stocklocation-detail'), + url(r'^$', LocationDetail.as_view(), name='api-location-detail'), ] stock_api_urls = [ diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 41dc730b41..e84554b89b 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -36,6 +36,19 @@ class StockLocation(InvenTreeTree): def has_items(self): return self.stock_items.count() > 0 + @property + def format_barcode(self): + """ Return a JSON string for formatting a barcode for this StockLocation object """ + + return helpers.MakeBarcode( + 'StockLocation', + reverse('api-location-detail', kwargs={'pk': self.id}), + { + 'id': self.id, + 'name': self.name, + } + ) + @receiver(pre_delete, sender=StockLocation, dispatch_uid='stocklocation_delete_log') def before_delete_stock_location(sender, instance, using, **kwargs): @@ -135,13 +148,18 @@ class StockItem(models.Model): { type: 'StockItem', stock_id: , part_id: } - Any other data should be looked up using the InvenTree API (as it may change) + Voltagile data (e.g. stock quantity) should be looked up using the InvenTree API (as it may change) """ - return helpers.MakeBarcode('StockItem', { - 'stock_id': self.id, - 'part_id': self.part.id - }) + return helpers.MakeBarcode( + 'StockItem', + reverse('api-stock-detail', kwargs={'pk': self.id}), + { + 'id': self.id, + 'part_id': self.part.id, + 'part_name': self.part.name + } + ) # The 'master' copy of the part of which this stock item is an instance part = models.ForeignKey('part.Part', on_delete=models.CASCADE, related_name='locations', help_text='Base part') diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 1483d8fc4f..16ba463ee2 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -1,5 +1,6 @@ {% extends "stock/stock_app_base.html" %} {% load static %} +{% load qr_code %} {% block content %}
@@ -25,6 +26,7 @@
  • Delete
  • + {% qr_from_text location.format_barcode size="s" image_format="png" error_correction="L" %} {% endif %}