fix(properties): source current SAP/EPC from baseline in the portfolio table

getProperties selected p.current_sap_points / p.current_epc_rating directly,
which are null for new-approach properties (headline columns unwritten on the
row). That made the Current EPC column blank and, since the Expected EPC column
is currentSapPoints + recommendation SAP, made Expected EPC show 0.

Use the sapSql / epcBandSql baseline helpers (lodged_sap_score / lodged_epc_band
for new-approach properties, property row for legacy), matching the reporting
page. Verified for properties that have a baseline row; the rest populate once
the baseline backfill completes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-06-23 08:37:30 +00:00
parent 04d9b45f0a
commit 5dd2179bef

View file

@ -26,6 +26,8 @@ import {
lodgementDateSql,
isExpiredSql,
mainfuelSql,
sapSql,
epcBandSql,
} from "@/lib/services/epcSources";
import {
FilterGroups,
@ -716,8 +718,11 @@ export async function getProperties(
p.postcode AS postcode,
p.status AS status,
p.creation_status AS "creationStatus",
p.current_epc_rating AS "currentEpcRating",
p.current_sap_points AS "currentSapPoints",
-- Current EPC/SAP: new-approach properties have null headline columns on
-- the property row, so source from the lodged baseline. The "Expected EPC"
-- column is currentSapPoints + recommendation SAP, so this also fixes it.
${epcBandSql} AS "currentEpcRating",
${sapSql} AS "currentSapPoints",
-- property_targets is no longer read (the "Expected EPC" column derives
-- from currentSapPoints + recommendation SAP). Kept as NULL to preserve
-- the PropertyWithRelations shape.