Skip to content

Commit

Permalink
Remove half hitas from regulated housing companies report
Browse files Browse the repository at this point in the history
  • Loading branch information
indigane committed May 27, 2024
1 parent 18d29ca commit 6d8bcd8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
3 changes: 3 additions & 0 deletions backend/hitas/services/housing_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ def find_regulated_housing_companies_for_reporting() -> list[HousingCompanyWithR
.filter(
regulation_status=RegulationStatus.REGULATED,
)
.exclude(
hitas_type=HitasType.HALF_HITAS,
)
.alias(
_acquisition_price=get_first_sale_acquisition_price("real_estates__buildings__apartments__id"),
)
Expand Down
4 changes: 0 additions & 4 deletions backend/hitas/services/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class RegulatedHousingCompaniesReportColumns(NamedTuple):
completion_date: datetime.date | str
apartment_count: int | str
average_price_per_square_meter: Decimal | str
half_hitas: str


class UnregulatedHousingCompaniesReportColumns(NamedTuple):
Expand Down Expand Up @@ -320,7 +319,6 @@ def build_regulated_housing_companies_report_excel(
completion_date="Valmistumispäivä",
apartment_count="Asuntojen lukumäärä",
average_price_per_square_meter="Keskineliöhinta",
half_hitas="Puolihitas",
)
worksheet.append(column_headers)

Expand All @@ -334,7 +332,6 @@ def build_regulated_housing_companies_report_excel(
completion_date=housing_company.completion_date,
apartment_count=housing_company.apartment_count,
average_price_per_square_meter=housing_company.avg_price_per_square_meter,
half_hitas="X" if housing_company.hitas_type.value == HitasType.HALF_HITAS.value else "",
),
)

Expand All @@ -349,7 +346,6 @@ def build_regulated_housing_companies_report_excel(
completion_date="",
apartment_count="",
average_price_per_square_meter="",
half_hitas="",
)

# There needs to be an empty row for sorting and filtering to work properly
Expand Down
30 changes: 19 additions & 11 deletions backend/hitas/tests/apis/test_api_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ def test__api__regulated_housing_companies_report__single_housing_company(api_cl
"Valmistumispäivä",
"Asuntojen lukumäärä",
"Keskineliöhinta",
"Puolihitas",
),
(
housing_company.postal_code.cost_area,
Expand All @@ -467,9 +466,8 @@ def test__api__regulated_housing_companies_report__single_housing_company(api_cl
datetime.datetime.fromisoformat(sale.apartment.completion_date.isoformat()),
1,
int(sale.total_price / sale.apartment.surface_area),
None,
),
(None, None, None, None, None, None, None, None), # Empty row at the bottom for filtering and sorting
(None, None, None, None, None, None, None), # Empty row at the bottom for filtering and sorting
]


Expand All @@ -492,7 +490,7 @@ def test__api__regulated_housing_companies_report__multiple_housing_companies(ap
housing_company_2: HousingCompany = HousingCompanyFactory.create(
postal_code__value="00002",
postal_code__cost_area=1,
hitas_type=HitasType.HALF_HITAS,
hitas_type=HitasType.HITAS_II,
)
sale_2: ApartmentSale = ApartmentSaleFactory.create(
purchase_date=datetime.date(2021, 1, 1),
Expand All @@ -518,7 +516,6 @@ def test__api__regulated_housing_companies_report__multiple_housing_companies(ap
"Valmistumispäivä",
"Asuntojen lukumäärä",
"Keskineliöhinta",
"Puolihitas",
),
(
housing_company_1.postal_code.cost_area,
Expand All @@ -528,7 +525,6 @@ def test__api__regulated_housing_companies_report__multiple_housing_companies(ap
datetime.datetime.fromisoformat(sale_1.apartment.completion_date.isoformat()),
1,
int(sale_1.total_price / sale_1.apartment.surface_area),
None,
),
(
housing_company_2.postal_code.cost_area,
Expand All @@ -538,9 +534,8 @@ def test__api__regulated_housing_companies_report__multiple_housing_companies(ap
datetime.datetime.fromisoformat(sale_2.apartment.completion_date.isoformat()),
1,
int(sale_2.total_price / sale_2.apartment.surface_area),
"X",
),
(None, None, None, None, None, None, None, None), # Empty row at the bottom for filtering and sorting
(None, None, None, None, None, None, None), # Empty row at the bottom for filtering and sorting
]


Expand Down Expand Up @@ -576,6 +571,21 @@ def test__api__regulated_housing_companies_report__unregulated_not_included(api_
apartment__building__real_estate__housing_company=housing_company_2,
)

# Housing company not included in the report since HALF_HITAS have a separate report
housing_company_3: HousingCompany = HousingCompanyFactory.create(
postal_code__value="00001",
postal_code__cost_area=1,
hitas_type=HitasType.HALF_HITAS,
)
ApartmentSaleFactory.create(
purchase_date=datetime.date(2020, 1, 1),
purchase_price=50_000,
apartment_share_of_housing_company_loans=10_000,
apartment__surface_area=100,
apartment__completion_date=datetime.date(2020, 1, 1),
apartment__building__real_estate__housing_company=housing_company_3,
)

url = reverse("hitas:regulated-housing-companies-report-list")
response: HttpResponse = api_client.get(url)

Expand All @@ -591,7 +601,6 @@ def test__api__regulated_housing_companies_report__unregulated_not_included(api_
"Valmistumispäivä",
"Asuntojen lukumäärä",
"Keskineliöhinta",
"Puolihitas",
),
(
housing_company_1.postal_code.cost_area,
Expand All @@ -601,9 +610,8 @@ def test__api__regulated_housing_companies_report__unregulated_not_included(api_
datetime.datetime.fromisoformat(sale_1.apartment.completion_date.isoformat()),
1,
int(sale_1.total_price / sale_1.apartment.surface_area),
None,
),
(None, None, None, None, None, None, None, None), # Empty row at the bottom for filtering and sorting
(None, None, None, None, None, None, None), # Empty row at the bottom for filtering and sorting
]


Expand Down

0 comments on commit 6d8bcd8

Please sign in to comment.