-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migration to add description type based on row type (HL-1046)
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
backend/benefit/calculator/migrations/0015_desc_type_for_old_calc_rows.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 3.2.18 on 2023-11-20 17:28 | ||
|
||
from django.db import migrations | ||
from calculator.enums import RowType, DescriptionType | ||
|
||
|
||
def add_description_type(apps, _): | ||
row_model = apps.get_model("calculator", "CalculationRow") | ||
for row in row_model.objects.filter(row_type=RowType.DESCRIPTION): | ||
if row.description_type: | ||
continue | ||
if row.description_fi.startswith("Ajalta"): | ||
row.description_type = DescriptionType.DATE | ||
elif row.description_fi.startswith("Koko ajalta"): | ||
row.description_type = DescriptionType.DATE_TOTAL | ||
elif row.description_fi.startswith("Vähennettävät korvaukset"): | ||
row.description_type = DescriptionType.DEDUCTION | ||
row.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("calculator", "0014_add_description_type_to_row"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
add_description_type, reverse_code=migrations.RunPython.noop | ||
), | ||
] |