Coverage for src/backend/InvenTree/stock/migrations/0085_auto_20220903_0225.py: 43%
20 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
1# Generated by Django 3.2.15 on 2022-09-03 02:25
3from django.db import migrations
6def uid_to_barcode(apps, schama_editor):
7 """Migrate old 'uid' field to new 'barcode_hash' field"""
9 StockItem = apps.get_model('stock', 'stockitem')
11 # Find all StockItem objects with non-empty UID field
12 items = StockItem.objects.exclude(uid=None).exclude(uid='')
14 for item in items: 14 ↛ 15line 14 didn't jump to line 15 because the loop on line 14 never started
15 item.barcode_hash = item.uid
16 item.save()
18 if items.count() > 0: 18 ↛ 19line 18 didn't jump to line 19 because the condition on line 18 was never true
19 print(f"Updated barcode data for {items.count()} StockItem objects")
21def barcode_to_uid(apps, schema_editor):
22 """Migrate new 'barcode_hash' field to old 'uid' field"""
24 StockItem = apps.get_model('stock', 'stockitem')
26 # Find all StockItem objects with non-empty UID field
27 items = StockItem.objects.exclude(barcode_hash=None).exclude(barcode_hash='')
29 for item in items:
30 item.uid = item.barcode_hash
31 item.save()
33 if items.count() > 0:
34 print(f"Updated barcode data for {items.count()} StockItem objects")
37class Migration(migrations.Migration):
39 dependencies = [
40 ('stock', '0084_auto_20220903_0154'),
41 ]
43 operations = [
44 migrations.RunPython(
45 uid_to_barcode,
46 reverse_code=barcode_to_uid
47 )
48 ]