Coverage for src/backend/InvenTree/company/migrations/0064_move_address_field_to_address_model.py: 38%

20 statements  

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

1# Generated by Django 3.2.18 on 2023-05-02 20:41 

2 

3from django.db import migrations 

4 

5def move_address_to_new_model(apps, schema_editor): 

6 Company = apps.get_model('company', 'Company') 

7 Address = apps.get_model('company', 'Address') 

8 for company in Company.objects.all(): 8 ↛ 9line 8 didn't jump to line 9 because the loop on line 8 never started

9 if company.address != '': 

10 # Address field might exceed length of new model fields 

11 l1 = company.address[:50] 

12 l2 = company.address[50:100] 

13 Address.objects.create(company=company, 

14 title="Primary", 

15 primary=True, 

16 line1=l1, 

17 line2=l2) 

18 company.address = '' 

19 company.save() 

20 

21def revert_address_move(apps, schema_editor): 

22 Address = apps.get_model('company', 'Address') 

23 for address in Address.objects.all(): 

24 address.company.address = f'{address.line1}{address.line2}' 

25 address.company.save() 

26 address.delete() 

27 

28 

29class Migration(migrations.Migration): 

30 

31 dependencies = [ 

32 ('company', '0063_auto_20230502_1956'), 

33 ] 

34 

35 operations = [ 

36 migrations.RunPython(move_address_to_new_model, reverse_code=revert_address_move) 

37 ]