Fix CompensationAction unit None
* adds correct declaration of unit (qm -> m2) for template rendering * adds migration to transform existing qm units to m2
This commit is contained in:
		
							parent
							
								
									7c4940729c
								
							
						
					
					
						commit
						814f35c426
					
				
							
								
								
									
										35
									
								
								compensation/migrations/0013_auto_20221117_0819.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								compensation/migrations/0013_auto_20221117_0819.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,35 @@
 | 
				
			|||||||
 | 
					# Generated by Django 3.1.3 on 2022-11-17 07:19
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from django.db import migrations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from compensation.models import UnitChoices
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def harmonize_action_units(apps, schema_editor):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    CompensationAction units (based on UnitChoices) can be mixed up at this point where
 | 
				
			||||||
 | 
					        * qm represents m²  and
 | 
				
			||||||
 | 
					        * m2 represents m²
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    We drop qm in support of m2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    CompensationAction = apps.get_model("compensation", "CompensationAction")
 | 
				
			||||||
 | 
					    actions = CompensationAction.objects.filter(
 | 
				
			||||||
 | 
					        unit="qm"
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for action in actions:
 | 
				
			||||||
 | 
					        action.unit = UnitChoices.m2
 | 
				
			||||||
 | 
					        action.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Migration(migrations.Migration):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dependencies = [
 | 
				
			||||||
 | 
					        ('compensation', '0012_auto_20221116_1322'),
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    operations = [
 | 
				
			||||||
 | 
					        migrations.RunPython(harmonize_action_units),
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
@ -19,8 +19,9 @@ class UnitChoices(models.TextChoices):
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
    cm = "cm", _("cm")
 | 
					    cm = "cm", _("cm")
 | 
				
			||||||
    m = "m", _("m")
 | 
					    m = "m", _("m")
 | 
				
			||||||
 | 
					    m2 = "m2", _("m²")
 | 
				
			||||||
 | 
					    m3 = "m3", _("m³")
 | 
				
			||||||
    km = "km", _("km")
 | 
					    km = "km", _("km")
 | 
				
			||||||
    qm = "qm", _("m²")
 | 
					 | 
				
			||||||
    ha = "ha", _("ha")
 | 
					    ha = "ha", _("ha")
 | 
				
			||||||
    st = "pcs", _("Pieces")  # pieces
 | 
					    st = "pcs", _("Pieces")  # pieces
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user