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

@@ -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."""

View File

@@ -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."""

View File

@@ -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'),

View File

@@ -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')

View File

@@ -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."""