Skip to content

Commit

Permalink
tasotarkistus: update model and attribute names
Browse files Browse the repository at this point in the history
  • Loading branch information
NC-jsAhonen committed Nov 29, 2024
1 parent a2271cf commit c06e0c2
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.utils.dateparse import parse_datetime

from leasing.models.rent import (
IndexNumberYearly,
IndexPointFigureYearly,
OldDwellingsInHousingCompaniesPriceIndex,
)

Expand Down Expand Up @@ -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,
},
Expand Down

This file was deleted.

95 changes: 95 additions & 0 deletions leasing/migrations/0083_indexpointfigureyearly_and_more.py
Original file line number Diff line number Diff line change
@@ -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"
),
),
]
4 changes: 2 additions & 2 deletions leasing/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
FixedInitialYearRent,
Index,
IndexAdjustedRent,
IndexNumberYearly,
IndexPointFigureYearly,
LeaseBasisOfRent,
LeaseBasisOfRentManagementSubvention,
LeaseBasisOfRentTemporarySubvention,
Expand Down Expand Up @@ -170,7 +170,7 @@
"Hitas",
"Index",
"IndexAdjustedRent",
"IndexNumberYearly",
"IndexPointFigureYearly",
"InfillDevelopmentCompensation",
"InfillDevelopmentCompensationAttachment",
"InfillDevelopmentCompensationDecision",
Expand Down
10 changes: 5 additions & 5 deletions leasing/models/rent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -1493,7 +1493,7 @@ class LegacyIndex(models.Model):
)


class IndexNumberYearly(TimeStampedModel):
class IndexPointFigureYearly(TimeStampedModel):
"""
In Finnish: Indeksipisteluku, vuosittain
Expand All @@ -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,
Expand Down
14 changes: 8 additions & 6 deletions leasing/serializers/rent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
FixedInitialYearRent,
Index,
IndexAdjustedRent,
IndexNumberYearly,
IndexPointFigureYearly,
LeaseBasisOfRent,
OldDwellingsInHousingCompaniesPriceIndex,
PayableRent,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c06e0c2

Please sign in to comment.