From c06e0c2f32a2473bd0f632cb056c1b3098c17191 Mon Sep 17 00:00:00 2001 From: Jukka Ahonen Date: Fri, 22 Nov 2024 12:51:40 +0000 Subject: [PATCH] tasotarkistus: update model and attribute names --- .../import_periodic_rent_adjustment_index.py | 10 +- ...emove_indexnumberyearly_number_and_more.py | 50 ---------- .../0083_indexpointfigureyearly_and_more.py | 95 +++++++++++++++++++ leasing/models/__init__.py | 4 +- leasing/models/rent.py | 10 +- leasing/serializers/rent.py | 14 +-- 6 files changed, 114 insertions(+), 69 deletions(-) delete mode 100644 leasing/migrations/0081_remove_indexnumberyearly_number_and_more.py create mode 100644 leasing/migrations/0083_indexpointfigureyearly_and_more.py diff --git a/leasing/management/commands/import_periodic_rent_adjustment_index.py b/leasing/management/commands/import_periodic_rent_adjustment_index.py index d7f1ad3c..58e6c8b6 100644 --- a/leasing/management/commands/import_periodic_rent_adjustment_index.py +++ b/leasing/management/commands/import_periodic_rent_adjustment_index.py @@ -7,7 +7,7 @@ from django.utils.dateparse import parse_datetime from leasing.models.rent import ( - IndexNumberYearly, + IndexPointFigureYearly, OldDwellingsInHousingCompaniesPriceIndex, ) @@ -316,17 +316,15 @@ def _update_or_create_index_numbers( for dp in data_points: year = int(dp["key"][year_key_pos]) - point_figure = _cast_index_number_to_float_or_none( - dp["values"][number_value_pos] - ) + value = _cast_index_number_to_float_or_none(dp["values"][number_value_pos]) region = dp["key"][region_key_pos] comment = _find_comment_for_value(dp, comments, columns) # TODO verify in 5.9. meeting: should we exclude "ennakkotieto" commented values? - _, created = IndexNumberYearly.objects.update_or_create( + _, created = IndexPointFigureYearly.objects.update_or_create( index=index, year=year, defaults={ - "point_figure": point_figure, + "value": value, "region": region, "comment": comment, }, diff --git a/leasing/migrations/0081_remove_indexnumberyearly_number_and_more.py b/leasing/migrations/0081_remove_indexnumberyearly_number_and_more.py deleted file mode 100644 index b1da3578..00000000 --- a/leasing/migrations/0081_remove_indexnumberyearly_number_and_more.py +++ /dev/null @@ -1,50 +0,0 @@ -# Generated by Django 4.2.16 on 2024-11-21 14:14 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ("leasing", "0080_alter_contact_options"), - ] - - operations = [ - migrations.RemoveField( - model_name="indexnumberyearly", - name="number", - ), - migrations.AddField( - model_name="indexnumberyearly", - name="point_figure", - field=models.DecimalField( - decimal_places=1, - max_digits=8, - null=True, - verbose_name="Index point figure", - ), - ), - migrations.AddField( - model_name="rent", - name="old_dwellings_in_housing_companies_price_index", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.PROTECT, - related_name="+", - to="leasing.olddwellingsinhousingcompaniespriceindex", - verbose_name="Old dwellings in housing companies price index", - ), - ), - migrations.AddField( - model_name="rent", - name="start_price_index_point_figure", - field=models.DecimalField( - decimal_places=1, - max_digits=8, - null=True, - verbose_name="Start price index point figure", - ), - ), - ] diff --git a/leasing/migrations/0083_indexpointfigureyearly_and_more.py b/leasing/migrations/0083_indexpointfigureyearly_and_more.py new file mode 100644 index 00000000..6f376510 --- /dev/null +++ b/leasing/migrations/0083_indexpointfigureyearly_and_more.py @@ -0,0 +1,95 @@ +# Generated by Django 4.2.16 on 2024-11-22 11:42 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("leasing", "0082_remove_rent_seasonal_end_day_and_more"), + ] + + operations = [ + migrations.CreateModel( + name="IndexPointFigureYearly", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "created_at", + models.DateTimeField( + auto_now_add=True, verbose_name="Time created" + ), + ), + ( + "modified_at", + models.DateTimeField(auto_now=True, verbose_name="Time modified"), + ), + ( + "value", + models.DecimalField( + decimal_places=1, max_digits=8, null=True, verbose_name="Value" + ), + ), + ("year", models.PositiveSmallIntegerField(verbose_name="Year")), + ( + "region", + models.CharField(blank=True, max_length=255, verbose_name="Region"), + ), + ("comment", models.TextField(blank=True, verbose_name="Comment")), + ( + "index", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="point_figures", + to="leasing.olddwellingsinhousingcompaniespriceindex", + verbose_name="Index", + ), + ), + ], + options={ + "verbose_name": "index number", + "verbose_name_plural": "index numbers", + "ordering": ("-index", "-year"), + }, + ), + migrations.AddField( + model_name="rent", + name="old_dwellings_in_housing_companies_price_index", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="leasing.olddwellingsinhousingcompaniespriceindex", + verbose_name="Old dwellings in housing companies price index", + ), + ), + migrations.AddField( + model_name="rent", + name="start_price_index_point_figure", + field=models.DecimalField( + decimal_places=1, + max_digits=8, + null=True, + verbose_name="Start price index point figure", + ), + ), + migrations.DeleteModel( + name="IndexNumberYearly", + ), + migrations.AddConstraint( + model_name="indexpointfigureyearly", + constraint=models.UniqueConstraint( + fields=("index", "year"), name="unique_price_index_number" + ), + ), + ] diff --git a/leasing/models/__init__.py b/leasing/models/__init__.py index a3298f90..f14f1f06 100644 --- a/leasing/models/__init__.py +++ b/leasing/models/__init__.py @@ -108,7 +108,7 @@ FixedInitialYearRent, Index, IndexAdjustedRent, - IndexNumberYearly, + IndexPointFigureYearly, LeaseBasisOfRent, LeaseBasisOfRentManagementSubvention, LeaseBasisOfRentTemporarySubvention, @@ -170,7 +170,7 @@ "Hitas", "Index", "IndexAdjustedRent", - "IndexNumberYearly", + "IndexPointFigureYearly", "InfillDevelopmentCompensation", "InfillDevelopmentCompensationAttachment", "InfillDevelopmentCompensationDecision", diff --git a/leasing/models/rent.py b/leasing/models/rent.py index ced27a74..74b4b434 100644 --- a/leasing/models/rent.py +++ b/leasing/models/rent.py @@ -832,7 +832,7 @@ def is_active_on_period(self, date_range_start, date_range_end): def set_start_price_index_point_figure(self): if self.old_dwellings_in_housing_companies_price_index: - start_index_number_yearly = IndexNumberYearly.objects.get( + start_index_number_yearly = IndexPointFigureYearly.objects.get( index=self.old_dwellings_in_housing_companies_price_index, year=self.start_date.year - 1, ) @@ -1493,7 +1493,7 @@ class LegacyIndex(models.Model): ) -class IndexNumberYearly(TimeStampedModel): +class IndexPointFigureYearly(TimeStampedModel): """ In Finnish: Indeksipisteluku, vuosittain @@ -1519,14 +1519,14 @@ class IndexNumberYearly(TimeStampedModel): OldDwellingsInHousingCompaniesPriceIndex, verbose_name=_("Index"), on_delete=models.PROTECT, - related_name="numbers", + related_name="point_figures", ) # max_digits is arbitrary for the number. No need to limit it, although 7 # should be enough if the numbers are at most in the 100s of thousands. # Largest index number in the system at the moment is year 1914's index # with a number around 260 000. - point_figure = models.DecimalField( - verbose_name=_("Index point figure"), + value = models.DecimalField( + verbose_name=_("Value"), decimal_places=1, max_digits=8, null=True, diff --git a/leasing/serializers/rent.py b/leasing/serializers/rent.py index 24c57478..ff593be9 100644 --- a/leasing/serializers/rent.py +++ b/leasing/serializers/rent.py @@ -14,7 +14,7 @@ FixedInitialYearRent, Index, IndexAdjustedRent, - IndexNumberYearly, + IndexPointFigureYearly, LeaseBasisOfRent, OldDwellingsInHousingCompaniesPriceIndex, PayableRent, @@ -51,20 +51,22 @@ class Meta: fields = "__all__" -class IndexNumberYearlySerializer(serializers.Serializer): +class IndexPointFigureYearlySerializer(serializers.Serializer): id = serializers.IntegerField(required=False) - point_figure = serializers.DecimalField(max_digits=8, decimal_places=1) + value = serializers.DecimalField(max_digits=8, decimal_places=1) year = serializers.IntegerField() region = serializers.CharField(max_length=255, required=False, allow_null=True) comment = serializers.CharField(required=False, allow_null=True) class Meta: - model = IndexNumberYearly - fields = ("id", "point_figure", "year", "region", "comment") + model = IndexPointFigureYearly + fields = ("id", "value", "year", "region", "comment") class OldDwellingsInHousingCompaniesPriceIndexSerializer(serializers.ModelSerializer): - numbers = IndexNumberYearlySerializer(many=True, required=False, allow_null=True) + point_figures = IndexPointFigureYearlySerializer( + many=True, required=False, allow_null=True + ) class Meta: model = OldDwellingsInHousingCompaniesPriceIndex