mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-03 12:10:59 +00:00
Barcode Refactor (#3640)
* define a simple model mixin class for barcode * Adds generic function for assigning a barcode to a model instance * StockItem model now implements the BarcodeMixin class * Implement simple unit tests for new code * Fix unit tests * Data migration for uid field * Remove references to old 'uid' field * Migration for removing old uid field from StockItem model * Bump API version * Change lookup_barcode to be a classmethod * Change barcode_model_type to be a class method * Cleanup for generic barcode scan and assign API: - Raise ValidationError as appropriate - Improved unit testing - Groundwork for future generic implementation * Further unit tests for barcode scanning * Adjust error messages for compatibility * Unit test fix * Fix hash_barcode function - Add unit tests to ensure it produces the same results as before the refactor * Add BarcodeMixin to Part model * Remove old format_barcode function from Part model * Further fixes for unit tests * Add support for assigning arbitrary barcode to Part instance - Simplify barcode API - Add more unit tests * More unit test fixes * Update unit test * Adds generic endpoint for unassigning barcode data * Update web dialog for unlinking a barcode * Template cleanup * Add Barcode mixin to StockLocation class * Add some simple unit tests for new model mixin * Support assigning / unassigning barcodes for StockLocation * remove failing outdated test * Update template to integrate new barcode support for StockLocation * Add BarcodeMixin to SupplierPart model * Adds QR code view for SupplierPart * Major simplification of barcode API endpoints - Separate existing barcode plugin into two separate classes - Simplify and consolidate the response from barcode scanning - Update unit testing * Yet more unit test fixes * Yet yet more unit test fixes
This commit is contained in:
23
InvenTree/stock/migrations/0084_auto_20220903_0154.py
Normal file
23
InvenTree/stock/migrations/0084_auto_20220903_0154.py
Normal file
@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.2.15 on 2022-09-03 01:54
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0083_stocklocation_icon'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='stockitem',
|
||||
name='barcode_data',
|
||||
field=models.CharField(blank=True, help_text='Third party barcode data', max_length=500, verbose_name='Barcode Data'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='stockitem',
|
||||
name='barcode_hash',
|
||||
field=models.CharField(blank=True, help_text='Unique hash of barcode data', max_length=128, verbose_name='Barcode Hash'),
|
||||
),
|
||||
]
|
48
InvenTree/stock/migrations/0085_auto_20220903_0225.py
Normal file
48
InvenTree/stock/migrations/0085_auto_20220903_0225.py
Normal file
@ -0,0 +1,48 @@
|
||||
# Generated by Django 3.2.15 on 2022-09-03 02:25
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def uid_to_barcode(apps, schama_editor):
|
||||
"""Migrate old 'uid' field to new 'barcode_hash' field"""
|
||||
|
||||
StockItem = apps.get_model('stock', 'stockitem')
|
||||
|
||||
# Find all StockItem objects with non-empty UID field
|
||||
items = StockItem.objects.exclude(uid=None).exclude(uid='')
|
||||
|
||||
for item in items:
|
||||
item.barcode_hash = item.uid
|
||||
item.save()
|
||||
|
||||
if items.count() > 0:
|
||||
print(f"Updated barcode data for {items.count()} StockItem objects")
|
||||
|
||||
def barcode_to_uid(apps, schema_editor):
|
||||
"""Migrate new 'barcode_hash' field to old 'uid' field"""
|
||||
|
||||
StockItem = apps.get_model('stock', 'stockitem')
|
||||
|
||||
# Find all StockItem objects with non-empty UID field
|
||||
items = StockItem.objects.exclude(barcode_hash=None).exclude(barcode_hash='')
|
||||
|
||||
for item in items:
|
||||
item.uid = item.barcode_hash
|
||||
item.save()
|
||||
|
||||
if items.count() > 0:
|
||||
print(f"Updated barcode data for {items.count()} StockItem objects")
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0084_auto_20220903_0154'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
uid_to_barcode,
|
||||
reverse_code=barcode_to_uid
|
||||
)
|
||||
]
|
17
InvenTree/stock/migrations/0086_remove_stockitem_uid.py
Normal file
17
InvenTree/stock/migrations/0086_remove_stockitem_uid.py
Normal file
@ -0,0 +1,17 @@
|
||||
# Generated by Django 3.2.15 on 2022-09-03 02:54
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0085_auto_20220903_0225'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='stockitem',
|
||||
name='uid',
|
||||
),
|
||||
]
|
23
InvenTree/stock/migrations/0087_auto_20220912_2341.py
Normal file
23
InvenTree/stock/migrations/0087_auto_20220912_2341.py
Normal file
@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.2.15 on 2022-09-12 23:41
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0086_remove_stockitem_uid'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='stocklocation',
|
||||
name='barcode_data',
|
||||
field=models.CharField(blank=True, help_text='Third party barcode data', max_length=500, verbose_name='Barcode Data'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='stocklocation',
|
||||
name='barcode_hash',
|
||||
field=models.CharField(blank=True, help_text='Unique hash of barcode data', max_length=128, verbose_name='Barcode Hash'),
|
||||
),
|
||||
]
|
Reference in New Issue
Block a user