From 5dd2179befd92679bafdbceca7e0a167485c6a5e Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 23 Jun 2026 08:37:30 +0000 Subject: [PATCH] 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) --- src/app/portfolio/[slug]/utils.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/portfolio/[slug]/utils.ts b/src/app/portfolio/[slug]/utils.ts index c6947ccf..40e612a5 100644 --- a/src/app/portfolio/[slug]/utils.ts +++ b/src/app/portfolio/[slug]/utils.ts @@ -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.