From b0ed41f06a3aec603d3e60b3ab81e95c4e60462b Mon Sep 17 00:00:00 2001 From: indigane Date: Mon, 27 May 2024 09:54:48 +0300 Subject: [PATCH] Remove half hitas from regulated housing companies report --- backend/hitas/services/housing_company.py | 3 ++ backend/hitas/services/reports.py | 4 --- backend/hitas/tests/apis/test_api_reports.py | 30 +++++++++++++------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/backend/hitas/services/housing_company.py b/backend/hitas/services/housing_company.py index 90c3ac159..e2862906a 100644 --- a/backend/hitas/services/housing_company.py +++ b/backend/hitas/services/housing_company.py @@ -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"), ) diff --git a/backend/hitas/services/reports.py b/backend/hitas/services/reports.py index 26f0b3e77..dafa52d6f 100644 --- a/backend/hitas/services/reports.py +++ b/backend/hitas/services/reports.py @@ -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): @@ -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) @@ -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 "", ), ) @@ -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 diff --git a/backend/hitas/tests/apis/test_api_reports.py b/backend/hitas/tests/apis/test_api_reports.py index a8c88ec9b..225b1d30b 100644 --- a/backend/hitas/tests/apis/test_api_reports.py +++ b/backend/hitas/tests/apis/test_api_reports.py @@ -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, @@ -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 ] @@ -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), @@ -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, @@ -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, @@ -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 ] @@ -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) @@ -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, @@ -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 ]