diff --git a/docs/docs/plugins/builtin/inventree_barcode.md b/docs/docs/plugins/builtin/inventree_barcode.md index ee7ba38b3d..2c8e10c97a 100644 --- a/docs/docs/plugins/builtin/inventree_barcode.md +++ b/docs/docs/plugins/builtin/inventree_barcode.md @@ -14,8 +14,8 @@ This plugin is a *mandatory* plugin, and is always enabled. This plugin provides selection of the barcode format to use when generating labels. The format can be selected from: -- **JSON Barcodes**: This format is used for generating barcodes in JSON format, which is a 'human readable' format. - **Short Barcodes**: This format is used for generating barcodes in a short format, which is a more compact representation of the barcode data. +- **JSON Barcodes**: This format is used for generating barcodes in JSON format, which is a more verbose format. This format is not recommended for use in production environments, as it can be more difficult to parse and may not be supported by all barcode scanners. It is supported for legacy purposes, and is not recommended for use in new deployments. Additionally, if the "Short Barcodes" format is selected, the user can specify the prefix used for the barcode. This prefix is used to identify the barcode format, and can be set to any value. The default value is `INV-` - although can be changed. diff --git a/src/backend/InvenTree/part/test_part.py b/src/backend/InvenTree/part/test_part.py index 5bb704a500..8bb2ca37e4 100644 --- a/src/backend/InvenTree/part/test_part.py +++ b/src/backend/InvenTree/part/test_part.py @@ -160,7 +160,7 @@ class PartTest(TestCase): p = Part.objects.get(pk=1) barcode = p.format_barcode() - self.assertEqual(barcode, '{"part": 1}') + self.assertEqual(barcode, 'INV-PA1') def test_str(self): """Test string representation of a Part.""" @@ -248,7 +248,7 @@ class PartTest(TestCase): def test_barcode(self): """Test barcode format functionality.""" barcode = self.r1.format_barcode() - self.assertEqual('{"part": 3}', barcode) + self.assertEqual('INV-PA3', barcode) def test_sell_pricing(self): """Check that the sell pricebreaks were loaded.""" diff --git a/src/backend/InvenTree/plugin/base/barcodes/test_barcode.py b/src/backend/InvenTree/plugin/base/barcodes/test_barcode.py index 9538ee7c88..cec6fc68ad 100644 --- a/src/backend/InvenTree/plugin/base/barcodes/test_barcode.py +++ b/src/backend/InvenTree/plugin/base/barcodes/test_barcode.py @@ -178,7 +178,7 @@ class BarcodeAPITest(InvenTreeAPITestCase): item = StockItem.objects.get(pk=522) data = self.generateBarcode('stockitem', item.pk, expected_code=200).data - self.assertEqual(data['barcode'], '{"stockitem": 522}') + self.assertEqual(data['barcode'], 'INV-SI522') def test_barcode_generation_invalid(self): """Test barcode generation for invalid model/pk.""" diff --git a/src/backend/InvenTree/plugin/builtin/barcodes/inventree_barcode.py b/src/backend/InvenTree/plugin/builtin/barcodes/inventree_barcode.py index 224885813d..10cf3189c8 100644 --- a/src/backend/InvenTree/plugin/builtin/barcodes/inventree_barcode.py +++ b/src/backend/InvenTree/plugin/builtin/barcodes/inventree_barcode.py @@ -26,7 +26,7 @@ class InvenTreeInternalBarcodePlugin(SettingsMixin, BarcodeMixin, InvenTreePlugi NAME = 'InvenTreeBarcode' TITLE = _('InvenTree Barcodes') DESCRIPTION = _('Provides native support for barcodes') - VERSION = '2.1.0' + VERSION = '2.2.0' AUTHOR = _('InvenTree contributors') SETTINGS = { @@ -37,7 +37,7 @@ class InvenTreeInternalBarcodePlugin(SettingsMixin, BarcodeMixin, InvenTreePlugi ('json', _('JSON barcodes (human readable)')), ('short', _('Short barcodes (space optimized)')), ], - 'default': 'json', + 'default': 'short', }, 'SHORT_BARCODE_PREFIX': { 'name': _('Short Barcode Prefix'), diff --git a/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py b/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py index 4d6ad741aa..1dc1eb90b2 100644 --- a/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py +++ b/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py @@ -355,14 +355,16 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase): def test_generation_inventree_json(self): """Test JSON barcode generation.""" + self.set_plugin_setting('INTERNAL_BARCODE_FORMAT', 'json') item = stock.models.StockLocation.objects.get(pk=5) data = self.generate('stocklocation', item.pk, expected_code=200).data self.assertEqual(data['barcode'], '{"stocklocation": 5}') - def test_generation_inventree_short(self): - """Test short barcode generation.""" + # Revert to default setting self.set_plugin_setting('INTERNAL_BARCODE_FORMAT', 'short') + def test_generation_inventree_short(self): + """Test short barcode generation.""" item = stock.models.StockLocation.objects.get(pk=5) # test with default prefix @@ -376,4 +378,3 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase): self.assertEqual(data['barcode'], f'{prefix}SL5') self.set_plugin_setting('SHORT_BARCODE_PREFIX', 'INV-') - self.set_plugin_setting('INTERNAL_BARCODE_FORMAT', 'json') diff --git a/src/backend/InvenTree/stock/tests.py b/src/backend/InvenTree/stock/tests.py index b3a86d31e3..9495432366 100644 --- a/src/backend/InvenTree/stock/tests.py +++ b/src/backend/InvenTree/stock/tests.py @@ -838,10 +838,17 @@ class StockBarcodeTest(StockTestBase): # Render simple barcode data for the StockItem barcode = item.barcode - self.assertEqual(barcode, '{"stockitem": 1}') + self.assertEqual(barcode, 'INV-SI1') def test_location_barcode_basics(self): """Simple tests for the StockLocation barcode integration.""" + # Set the barcode plugin to use the legacy barcode format + from plugin.registry import registry + + plugin = registry.get_plugin('inventreebarcode') + + plugin.set_setting('INTERNAL_BARCODE_FORMAT', 'json') + self.assertEqual(StockLocation.barcode_model_type(), 'stocklocation') loc = StockLocation.objects.get(pk=1) @@ -849,6 +856,9 @@ class StockBarcodeTest(StockTestBase): barcode = loc.format_barcode() self.assertEqual('{"stocklocation": 1}', barcode) + # Revert the barcode format to the default + plugin.set_setting('INTERNAL_BARCODE_FORMAT', 'short') + class VariantTest(StockTestBase): """Tests for calculation stock counts against templates / variants."""