Coverage for src/backend/InvenTree/common/migrations/0001_initial.py: 78%

18 statements  

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

1# Generated by Django 2.2.4 on 2019-09-02 23:02 

2 

3import django.core.validators 

4from django.db import migrations, models 

5 

6 

7class CreateModelOrSkip(migrations.CreateModel): 

8 """Custom migration operation to create a model if it does not already exist. 

9 

10 - If the model already exists, the migration is skipped 

11 - This class has been added to deal with some errors being thrown in CI tests 

12 - The 'common_currency' table doesn't exist anymore anyway! 

13 - In the future, these migrations will be squashed 

14 """ 

15 

16 def database_forwards(self, app_label, schema_editor, from_state, to_state) -> None: 

17 """Forwards migration *attempts* to create the model, but will fail gracefully if it already exists""" 

18 

19 try: 

20 super().database_forwards(app_label, schema_editor, from_state, to_state) 

21 except Exception: # pragma: no cover 

22 pass 

23 

24 def state_forwards(self, app_label, state) -> None: 

25 try: 

26 super().state_forwards(app_label, state) 

27 except Exception: # pragma: no cover 

28 pass 

29 

30 

31class Migration(migrations.Migration): 

32 

33 initial = True 

34 atomic = False 

35 

36 dependencies = [ 

37 ] 

38 

39 operations = [ 

40 CreateModelOrSkip( 

41 name='Currency', 

42 fields=[ 

43 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 

44 ('symbol', models.CharField(help_text='Currency Symbol e.g. $', max_length=10)), 

45 ('suffix', models.CharField(help_text='Currency Suffix e.g. AUD', max_length=10, unique=True)), 

46 ('description', models.CharField(help_text='Currency Description', max_length=100)), 

47 ('value', models.DecimalField(decimal_places=5, help_text='Currency Value', max_digits=10, validators=[django.core.validators.MinValueValidator(1e-05), django.core.validators.MaxValueValidator(100000)])), 

48 ('base', models.BooleanField(default=False, help_text='Use this currency as the base currency')), 

49 ], 

50 ), 

51 ]