Coverage for src/backend/InvenTree/stock/migrations/0081_auto_20220801_0044.py: 40%
19 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.14 on 2022-08-01 00:44
3from django.db import migrations
5from InvenTree.helpers import constructPathString
8def update_pathstring(apps, schema_editor):
9 """Construct pathstring for all existing StockLocation objects"""
11 StockLocation = apps.get_model('stock', 'stocklocation')
13 n = StockLocation.objects.count()
15 if n > 0: 15 ↛ 17line 15 didn't jump to line 17 because the condition on line 15 was never true
17 for loc in StockLocation.objects.all():
19 # Construct complete path for category
20 path = [loc.name]
22 parent = loc.parent
24 # Iterate up the tree
25 while parent is not None:
26 path = [parent.name] + path
27 parent = parent.parent
29 pathstring = constructPathString(path)
31 loc.pathstring = pathstring
32 loc.save()
34 print(f"\n--- Updated 'pathstring' for {n} StockLocation objects ---\n")
37class Migration(migrations.Migration):
39 dependencies = [
40 ('stock', '0080_stocklocation_pathstring'),
41 ]
43 operations = [
44 migrations.RunPython(
45 update_pathstring,
46 reverse_code=migrations.RunPython.noop
47 )
48 ]