Coverage for src/backend/InvenTree/common/migrations/0010_migrate_currency_setting.py: 67%

14 statements  

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

1# Generated by Django 3.2.4 on 2021-07-01 15:39 

2 

3from django.db import migrations 

4from common.models import InvenTreeSetting 

5from InvenTree.config import get_setting 

6 

7def set_default_currency(apps, schema_editor): 

8 """ migrate the currency setting from config.yml to db """ 

9 # get value from settings-file 

10 base_currency = get_setting('INVENTREE_BASE_CURRENCY', 'base_currency', 'USD') 

11 

12 from common.currency import currency_codes 

13 

14 # check if value is valid 

15 if base_currency not in currency_codes(): 15 ↛ 16line 15 didn't jump to line 16 because the condition on line 15 was never true

16 if len (currency_codes()) > 0: 

17 base_currency = currency_codes()[0] 

18 else: 

19 base_currency = 'USD' 

20 

21 # write to database 

22 InvenTreeSetting.set_setting('INVENTREE_DEFAULT_CURRENCY', base_currency, None, create=True) 

23 

24 

25class Migration(migrations.Migration): 

26 

27 dependencies = [ 

28 ('common', '0009_delete_currency'), 

29 ] 

30 

31 operations = [ 

32 migrations.RunPython(set_default_currency, reverse_code=migrations.RunPython.noop), 

33 ]