2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-02-19 13:18:03 +00:00

Change default barcode type (#11304)

* Change default barcode type

* Bump plugin version

* Adjust unit testing

* Tweak unit tests

* Tweak docs
This commit is contained in:
Oliver
2026-02-17 00:22:44 +11:00
committed by GitHub
parent 430dfbbae5
commit 033ad420ce
6 changed files with 21 additions and 10 deletions

View File

@@ -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: 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. - **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. 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.

View File

@@ -160,7 +160,7 @@ class PartTest(TestCase):
p = Part.objects.get(pk=1) p = Part.objects.get(pk=1)
barcode = p.format_barcode() barcode = p.format_barcode()
self.assertEqual(barcode, '{"part": 1}') self.assertEqual(barcode, 'INV-PA1')
def test_str(self): def test_str(self):
"""Test string representation of a Part.""" """Test string representation of a Part."""
@@ -248,7 +248,7 @@ class PartTest(TestCase):
def test_barcode(self): def test_barcode(self):
"""Test barcode format functionality.""" """Test barcode format functionality."""
barcode = self.r1.format_barcode() barcode = self.r1.format_barcode()
self.assertEqual('{"part": 3}', barcode) self.assertEqual('INV-PA3', barcode)
def test_sell_pricing(self): def test_sell_pricing(self):
"""Check that the sell pricebreaks were loaded.""" """Check that the sell pricebreaks were loaded."""

View File

@@ -178,7 +178,7 @@ class BarcodeAPITest(InvenTreeAPITestCase):
item = StockItem.objects.get(pk=522) item = StockItem.objects.get(pk=522)
data = self.generateBarcode('stockitem', item.pk, expected_code=200).data 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): def test_barcode_generation_invalid(self):
"""Test barcode generation for invalid model/pk.""" """Test barcode generation for invalid model/pk."""

View File

@@ -26,7 +26,7 @@ class InvenTreeInternalBarcodePlugin(SettingsMixin, BarcodeMixin, InvenTreePlugi
NAME = 'InvenTreeBarcode' NAME = 'InvenTreeBarcode'
TITLE = _('InvenTree Barcodes') TITLE = _('InvenTree Barcodes')
DESCRIPTION = _('Provides native support for barcodes') DESCRIPTION = _('Provides native support for barcodes')
VERSION = '2.1.0' VERSION = '2.2.0'
AUTHOR = _('InvenTree contributors') AUTHOR = _('InvenTree contributors')
SETTINGS = { SETTINGS = {
@@ -37,7 +37,7 @@ class InvenTreeInternalBarcodePlugin(SettingsMixin, BarcodeMixin, InvenTreePlugi
('json', _('JSON barcodes (human readable)')), ('json', _('JSON barcodes (human readable)')),
('short', _('Short barcodes (space optimized)')), ('short', _('Short barcodes (space optimized)')),
], ],
'default': 'json', 'default': 'short',
}, },
'SHORT_BARCODE_PREFIX': { 'SHORT_BARCODE_PREFIX': {
'name': _('Short Barcode Prefix'), 'name': _('Short Barcode Prefix'),

View File

@@ -355,14 +355,16 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase):
def test_generation_inventree_json(self): def test_generation_inventree_json(self):
"""Test JSON barcode generation.""" """Test JSON barcode generation."""
self.set_plugin_setting('INTERNAL_BARCODE_FORMAT', 'json')
item = stock.models.StockLocation.objects.get(pk=5) item = stock.models.StockLocation.objects.get(pk=5)
data = self.generate('stocklocation', item.pk, expected_code=200).data data = self.generate('stocklocation', item.pk, expected_code=200).data
self.assertEqual(data['barcode'], '{"stocklocation": 5}') self.assertEqual(data['barcode'], '{"stocklocation": 5}')
def test_generation_inventree_short(self): # Revert to default setting
"""Test short barcode generation."""
self.set_plugin_setting('INTERNAL_BARCODE_FORMAT', 'short') 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) item = stock.models.StockLocation.objects.get(pk=5)
# test with default prefix # test with default prefix
@@ -376,4 +378,3 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase):
self.assertEqual(data['barcode'], f'{prefix}SL5') self.assertEqual(data['barcode'], f'{prefix}SL5')
self.set_plugin_setting('SHORT_BARCODE_PREFIX', 'INV-') self.set_plugin_setting('SHORT_BARCODE_PREFIX', 'INV-')
self.set_plugin_setting('INTERNAL_BARCODE_FORMAT', 'json')

View File

@@ -838,10 +838,17 @@ class StockBarcodeTest(StockTestBase):
# Render simple barcode data for the StockItem # Render simple barcode data for the StockItem
barcode = item.barcode barcode = item.barcode
self.assertEqual(barcode, '{"stockitem": 1}') self.assertEqual(barcode, 'INV-SI1')
def test_location_barcode_basics(self): def test_location_barcode_basics(self):
"""Simple tests for the StockLocation barcode integration.""" """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') self.assertEqual(StockLocation.barcode_model_type(), 'stocklocation')
loc = StockLocation.objects.get(pk=1) loc = StockLocation.objects.get(pk=1)
@@ -849,6 +856,9 @@ class StockBarcodeTest(StockTestBase):
barcode = loc.format_barcode() barcode = loc.format_barcode()
self.assertEqual('{"stocklocation": 1}', barcode) self.assertEqual('{"stocklocation": 1}', barcode)
# Revert the barcode format to the default
plugin.set_setting('INTERNAL_BARCODE_FORMAT', 'short')
class VariantTest(StockTestBase): class VariantTest(StockTestBase):
"""Tests for calculation stock counts against templates / variants.""" """Tests for calculation stock counts against templates / variants."""