diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index f86a61e80d..605cc5cfb6 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -46,7 +46,7 @@ def WrapWithQuotes(text, quote='"'): return text -def MakeBarcode(object_type, object_url, data={}): +def MakeBarcode(object_type, object_id, object_url, data={}): """ Generate a string for a barcode. Adds some global InvenTree parameters. Args: @@ -60,6 +60,7 @@ def MakeBarcode(object_type, object_url, data={}): # Add in some generic InvenTree data data['type'] = object_type + data['id'] = object_id data['url'] = object_url data['tool'] = 'InvenTree' data['generated'] = str(datetime.now().date()) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index ab83b584cd..0e59eb67a3 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -21,6 +21,7 @@ from django.core.validators import MinValueValidator from django.db.models.signals import pre_delete from django.dispatch import receiver +from InvenTree import helpers from InvenTree.models import InvenTreeTree from company.models import Company @@ -179,6 +180,16 @@ class Part(models.Model): def __str__(self): return "{n} - {d}".format(n=self.name, d=self.description) + @property + def format_barcode(self): + """ Return a JSON string for formatting a barcode for this Part object """ + + return helpers.MakeBarcode( + "Part", + self.id, + reverse('api-part-detail', kwargs={'pk': self.id}), + ) + class Meta: verbose_name = "Part" verbose_name_plural = "Parts" diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 7b148318c9..f5941a7870 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -1,5 +1,6 @@ {% extends "part/part_base.html" %} {% load static %} +{% load qr_code %} {% block details %} {% include 'part/tabs.html' with tab='detail' %} @@ -115,6 +116,8 @@ {% endif %} +{% qr_from_text part.format_barcode size="s" image_format="png" error_correction="L" %} + {% endblock %} {% block js_load %} diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index e84554b89b..7cdc45b7bc 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -42,9 +42,9 @@ class StockLocation(InvenTreeTree): return helpers.MakeBarcode( 'StockLocation', + self.id, reverse('api-location-detail', kwargs={'pk': self.id}), { - 'id': self.id, 'name': self.name, } ) @@ -153,9 +153,9 @@ class StockItem(models.Model): return helpers.MakeBarcode( 'StockItem', + self.id, reverse('api-stock-detail', kwargs={'pk': self.id}), { - 'id': self.id, 'part_id': self.part.id, 'part_name': self.part.name }