Skip to content

Commit

Permalink
rent model: set_start_price_index_point_figure method
Browse files Browse the repository at this point in the history
  • Loading branch information
NC-jsAhonen committed Nov 29, 2024
1 parent c06e0c2 commit 7ea4fcd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
4 changes: 2 additions & 2 deletions leasing/models/rent.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,9 +834,9 @@ def set_start_price_index_point_figure(self):
if self.old_dwellings_in_housing_companies_price_index:
start_index_number_yearly = IndexPointFigureYearly.objects.get(
index=self.old_dwellings_in_housing_companies_price_index,
year=self.start_date.year - 1,
year=self.lease.start_date.year - 1,
)
self.start_price_index_point_figure = start_index_number_yearly.point_figure
self.start_price_index_point_figure = start_index_number_yearly.value


class RentDueDate(TimeStampedSafeDeleteModel):
Expand Down
19 changes: 18 additions & 1 deletion leasing/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@
LandUseAgreementType,
)
from leasing.models.receivable_type import ReceivableType
from leasing.models.rent import OldDwellingsInHousingCompaniesPriceIndex
from leasing.models.rent import (
IndexPointFigureYearly,
OldDwellingsInHousingCompaniesPriceIndex,
)
from leasing.models.service_unit import ServiceUnitGroupMapping
from leasing.models.tenant import TenantRentShare

Expand Down Expand Up @@ -145,6 +148,20 @@ class Meta:
model = Rent


@register
class OldDwellingsInHousingCompaniesPriceIndexFactory(
factory.django.DjangoModelFactory
):
class Meta:
model = OldDwellingsInHousingCompaniesPriceIndex


@register
class IndexPointFigureYearlyFactory(factory.django.DjangoModelFactory):
class Meta:
model = IndexPointFigureYearly


@register
class ContractRentFactory(factory.django.DjangoModelFactory):
class Meta:
Expand Down
48 changes: 47 additions & 1 deletion leasing/tests/models/test_rent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RentCycle,
RentType,
)
from leasing.models import Index, RentAdjustment, RentDueDate
from leasing.models import Index, Rent, RentAdjustment, RentDueDate
from leasing.models.utils import DayMonth


Expand Down Expand Up @@ -2841,3 +2841,49 @@ def test_is_the_last_billing_period(
rent.save()

assert rent.is_the_last_billing_period(billing_period) == expected


@pytest.mark.django_db
def test_set_start_price_index_point_figure_without_index(rent_factory, lease_factory):
"""The point figure should be None if the rent has no old_dwellings_in_housing_companies_price_index."""
lease = lease_factory()
rent: Rent = rent_factory(lease=lease)

rent.set_start_price_index_point_figure()

assert rent.start_price_index_point_figure is None


@pytest.mark.django_db
def test_set_start_price_index_point_figure_with_last_year_index(
rent_factory,
lease_factory,
old_dwellings_in_housing_companies_price_index_factory,
index_point_figure_yearly_factory,
):
"""The point figure should be set if rent has old_dwellings_in_housing_companies_price_index
and it should be the year previous to the LEASE's start date."""
lease = lease_factory(start_date=date(year=2024, month=1, day=1))
old_dwellings_in_housing_companies_price_index = (
old_dwellings_in_housing_companies_price_index_factory()
)
index_point_figure_yearly_factory(
value=101, year=2021, index=old_dwellings_in_housing_companies_price_index
)
index_point_figure_yearly_factory(
value=102, year=2022, index=old_dwellings_in_housing_companies_price_index
)
expected_point_figure = index_point_figure_yearly_factory(
value=103, year=2023, index=old_dwellings_in_housing_companies_price_index
)
index_point_figure_yearly_factory(
value=104, year=2024, index=old_dwellings_in_housing_companies_price_index
)
rent: Rent = rent_factory(
lease=lease,
old_dwellings_in_housing_companies_price_index=old_dwellings_in_housing_companies_price_index,
)

rent.set_start_price_index_point_figure()

assert rent.start_price_index_point_figure == expected_point_figure.value

0 comments on commit 7ea4fcd

Please sign in to comment.