Coverage for src/backend/InvenTree/part/migrations/0129_auto_20240815_0214.py: 75%

10 statements  

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

1# Generated by Django 4.2.15 on 2024-08-15 02:14 

2 

3from django.db import migrations 

4 

5 

6def set_testable(apps, schema_editor): 

7 """Set the 'testable' status to True for certain parts. 

8 

9 Prior to migration part.0128, the 'trackable' attribute 

10 was used to determine if parts could have tests associated with them. 

11 

12 However, 'trackable' comes with other restrictions 

13 (such as requiring a unique serial number). 

14 

15 So, we have added a new field 'testable' to the Part model, 

16 which is updated in this migration to match the value of the 'trackable' field. 

17 """ 

18 

19 Part = apps.get_model('part', 'Part') 

20 

21 # By default, 'testable' is False - so we only need to update parts marked as 'trackable' 

22 trackable_parts = Part.objects.filter(trackable=True) 

23 

24 if trackable_parts.count() > 0: 24 ↛ 25line 24 didn't jump to line 25 because the condition on line 24 was never true

25 print(f"\nMarking {trackable_parts.count()} Part objects as 'testable'") 

26 trackable_parts.update(testable=True) 

27 

28 

29class Migration(migrations.Migration): 

30 

31 dependencies = [ 

32 ('part', '0128_part_testable'), 

33 ] 

34 

35 operations = [ 

36 migrations.RunPython(set_testable, reverse_code=migrations.RunPython.noop) 

37 ]