From 2d412e2be10ffb3bb1bacac44dddbf7de99572b4 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 21 Jan 2021 20:55:13 +1100 Subject: [PATCH 1/4] Default to using "simple" QR codes --- 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 6b76c7d41b..61172cfc62 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 """ - brief = kwargs.get('brief', False) + brief = kwargs.get('brief', True) data = {} From 03f7baf87f34a31be5a2b07be918abbd3c68eb4f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 22 Jan 2021 09:50:30 +1100 Subject: [PATCH 2/4] Unit test fixes --- InvenTree/InvenTree/helpers.py | 2 +- InvenTree/InvenTree/tests.py | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 61172cfc62..99dc255dac 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -267,7 +267,7 @@ def WrapWithQuotes(text, quote='"'): return text -def MakeBarcode(object_name, object_pk, object_data, **kwargs): +def MakeBarcode(object_name, object_pk, object_data={}, **kwargs): """ Generate a string for a barcode. Adds some global InvenTree parameters. Args: diff --git a/InvenTree/InvenTree/tests.py b/InvenTree/InvenTree/tests.py index 6630c0b0af..96f32e7f57 100644 --- a/InvenTree/InvenTree/tests.py +++ b/InvenTree/InvenTree/tests.py @@ -1,4 +1,6 @@ +import json + from django.test import TestCase import django.core.exceptions as django_exceptions from django.core.exceptions import ValidationError @@ -134,7 +136,7 @@ class TestIncrement(TestCase): class TestMakeBarcode(TestCase): """ Tests for barcode string creation """ - def test_barcode(self): + def test_barcode_extended(self): bc = helpers.MakeBarcode( "part", @@ -142,13 +144,30 @@ class TestMakeBarcode(TestCase): { "id": 3, "url": "www.google.com", - } + }, + brief=False ) self.assertIn('part', bc) self.assertIn('tool', bc) self.assertIn('"tool": "InvenTree"', bc) + data = json.loads(bc) + + self.assertEqual(data['part']['id'], 3) + self.assertEqual(data['part']['url'], 'www.google.com') + + def test_barcode_brief(self): + + bc = helpers.MakeBarcode( + "stockitem", + 7, + ) + + data = json.loads(bc) + self.assertEqual(len(data), 1) + self.assertEqual(data['stockitem'], 7) + class TestDownloadFile(TestCase): From 5c9dd93ff1faaa883ef7353165619cc82a46280d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 22 Jan 2021 12:22:29 +1100 Subject: [PATCH 3/4] More unit test fix --- InvenTree/stock/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/stock/tests.py b/InvenTree/stock/tests.py index b0b05b6326..d232d3ab3d 100644 --- a/InvenTree/stock/tests.py +++ b/InvenTree/stock/tests.py @@ -122,7 +122,7 @@ class StockTest(TestCase): self.assertEqual(self.home.get_absolute_url(), '/stock/location/1/') def test_barcode(self): - barcode = self.office.format_barcode() + barcode = self.office.format_barcode(brief=False) self.assertIn('"name": "Office"', barcode) From 43e03ed02306c7e29420a372223411dfbb39d9ea Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 1 Feb 2021 12:26:58 +1100 Subject: [PATCH 4/4] Update unit tests --- InvenTree/barcode/barcode.py | 2 ++ InvenTree/part/test_part.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/InvenTree/barcode/barcode.py b/InvenTree/barcode/barcode.py index 3837fef599..004182e0be 100644 --- a/InvenTree/barcode/barcode.py +++ b/InvenTree/barcode/barcode.py @@ -25,6 +25,8 @@ def hash_barcode(barcode_data): TODO: Work out a way around this! """ + barcode_data = str(barcode_data).strip() + printable_chars = filter(lambda x: x in string.printable, barcode_data) barcode_data = ''.join(list(printable_chars)) diff --git a/InvenTree/part/test_part.py b/InvenTree/part/test_part.py index 4c08911122..030d7faf4e 100644 --- a/InvenTree/part/test_part.py +++ b/InvenTree/part/test_part.py @@ -100,7 +100,7 @@ class PartTest(TestCase): self.assertEqual(r.available_stock, 0) def test_barcode(self): - barcode = self.r1.format_barcode() + barcode = self.r1.format_barcode(brief=False) self.assertIn('InvenTree', barcode) self.assertIn(self.r1.name, barcode)