Commercial Real Estate Calculator

Overview

The commercial real estate (næringseiendom) valuation calculator has two implementations.

  • Backend (authoritative): tritt.finsta.service.assreg.calculator.CommercialRealEstateCalculator in finsta-service, with year-specific classes (CommercialRealEstateCalculator_2023, _2024, _2025).

  • Frontend (reactive subset): commercial-real-estate.calculator-utils.ts in finsta-frontend.

The backend is the source of truth. The frontend computes only the fields that need instant reactivity; the rest are populated on save/sync by the backend.

The FE/BE Split

Fields mirrored on both sides

The frontend updates these reactively as the user types; the backend overwrites them on save.

  • convertedGrossRentalIncome

  • stipulatedRentalIncome

  • averageRentalIncome

  • rentalValueFromCalculations

  • adjustedMarketValue

  • rentalValueBeforeValuationDiscount

  • taxValueAfterValuationDiscount

  • rentalValueOfPercentageBeforeValuationDiscount

  • taxValueOfPercentageAfterValuationDiscount

Fields computed only on the backend

These are visible in the UI but update only after save.

  • differenceBetweenCalculatedAndDocumentedValue

  • districtDiscount (2023 only)

Keeping Frontend and Backend in Sync

Parity between the two implementations is enforced by shared JSON test fixtures at finsta-frontend/tests/shared-fixtures/commercial-real-estate-shared-test-spec.json. Both the backend Spock tests (CommercialRealEstateCalculator_YYYYTest.groovy) and the frontend unit tests (commercial-real-estate.calculators.spec.ts) read from this file and assert against the same expected values.

A runtime safety net compares frontend-sent and backend-calculated values during sync and logs a warning on divergence (CommercialRealEstateReconciler).

Adding a New Year

  1. Add a new CommercialRealEstateCalculator_YYYY.groovy modelled on the most recent year.

  2. Update the CommercialRealEstateCalculator dispatcher to route YYYY to the new class.

  3. Add a new frontend file commercial-real-estate.calculator-YYYY.ts modelled on the most recent year.

  4. Add scenarios for the new year in finsta-frontend/tests/shared-fixtures/commercial-real-estate-shared-test-spec.json.

  5. Add a new backend test class CommercialRealEstateCalculator_YYYYTest.groovy reading the fixtures.

  6. The frontend test picks up the new scenarios automatically.

Adding a New Calculated Field

  1. Decide whether it needs reactivity on the frontend. Does it update visually as the user types, or is it acceptable to appear only after save?

  2. Add the calculation to the backend: in CommercialRealEstateCalculatorUtils if shared across years, or in year-specific calculators if year-varying.

  3. If reactive: mirror the calculation in the frontend calculator, and add a reminder comment pointing at the backend.

  4. Add test scenarios for the new field in the shared fixtures.

  5. Ensure the field is added to SpecificationOfCommercialPropertyEntity if not already there, and to SpecificationOfCommercialProperty on the API side.