From 1bf72ee335234940ddb74b93a136d344c3115da3 Mon Sep 17 00:00:00 2001 From: eeintech Date: Wed, 14 Apr 2021 16:00:28 -0400 Subject: [PATCH 1/2] Added revision and stock item URL for label creation --- InvenTree/InvenTree/helpers.py | 16 +++++++++++++++- InvenTree/label/models.py | 2 ++ InvenTree/stock/models.py | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index c2441590f5..e5324ba35a 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -280,11 +280,25 @@ def MakeBarcode(object_name, object_pk, object_data={}, **kwargs): json string of the supplied data plus some other data """ + url = kwargs.get('url', True) brief = kwargs.get('brief', True) data = {} - if brief: + if url: + request = object_data.get('request', None) + item_url = object_data.get('item_url', None) + absolute_url = None + + if request and item_url: + absolute_url = request.build_absolute_uri(item_url) + # Return URL (No JSON) + return absolute_url + + if item_url: + # Return URL (No JSON) + return item_url + elif brief: data[object_name] = object_pk else: data['tool'] = 'InvenTree' diff --git a/InvenTree/label/models.py b/InvenTree/label/models.py index 96850f4cb0..5c1b104670 100644 --- a/InvenTree/label/models.py +++ b/InvenTree/label/models.py @@ -253,10 +253,12 @@ class StockItemLabel(LabelTemplate): 'part': stock_item.part, 'name': stock_item.part.full_name, 'ipn': stock_item.part.IPN, + 'revision': stock_item.part.revision, 'quantity': normalize(stock_item.quantity), 'serial': stock_item.serial, 'uid': stock_item.uid, 'qr_data': stock_item.format_barcode(brief=True), + 'qr_url': stock_item.format_barcode(url=True, request=request), 'tests': stock_item.testResultMap() } diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index b57f96d0f7..ed86a807e1 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -344,6 +344,8 @@ class StockItem(MPTTModel): "stockitem", self.id, { + "request": kwargs.get('request', None), + "item_url": reverse('stock-item-detail', kwargs={'pk': self.id}), "url": reverse('api-stock-detail', kwargs={'pk': self.id}), }, **kwargs From aa41e3e17d3f29ff0926b36778ce47581703fc83 Mon Sep 17 00:00:00 2001 From: eeintech Date: Wed, 14 Apr 2021 16:24:24 -0400 Subject: [PATCH 2/2] Fixed default url barcode setting --- InvenTree/InvenTree/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index e5324ba35a..6f6953ccb5 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -280,7 +280,7 @@ def MakeBarcode(object_name, object_pk, object_data={}, **kwargs): json string of the supplied data plus some other data """ - url = kwargs.get('url', True) + url = kwargs.get('url', False) brief = kwargs.get('brief', True) data = {}