Coverage for src/backend/InvenTree/part/migrations/0121_auto_20240207_0344.py: 69%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 17:47 +0000

1# Generated by Django 4.2.9 on 2024-02-07 03:44 

2 

3from django.db import migrations 

4 

5 

6def set_key(apps, schema_editor): 

7 """Create a 'key' value for existing PartTestTemplate objects.""" 

8 

9 import InvenTree.helpers 

10 

11 PartTestTemplate = apps.get_model('part', 'PartTestTemplate') 

12 

13 for template in PartTestTemplate.objects.all(): 13 ↛ 14line 13 didn't jump to line 14 because the loop on line 13 never started

14 template.key = InvenTree.helpers.generateTestKey(str(template.test_name).strip()) 

15 template.save() 

16 

17 if PartTestTemplate.objects.count() > 0: 17 ↛ 18line 17 didn't jump to line 18 because the condition on line 17 was never true

18 print(f"\nUpdated 'key' value for {PartTestTemplate.objects.count()} PartTestTemplate objects") 

19 

20 

21class Migration(migrations.Migration): 

22 

23 dependencies = [ 

24 ('part', '0120_parttesttemplate_key'), 

25 ] 

26 

27 operations = [ 

28 migrations.RunPython(set_key, reverse_code=migrations.RunPython.noop) 

29 ]