diff --git a/domain/scenario_export/scenario_sheet.py b/domain/scenario_export/scenario_sheet.py index 7a0ebfb68..3d9dfda7b 100644 --- a/domain/scenario_export/scenario_sheet.py +++ b/domain/scenario_export/scenario_sheet.py @@ -41,6 +41,9 @@ MEASURE_COLUMNS: tuple[str, ...] = ( "system_tune_up_zoned", ) +# Property identity columns, leading every sheet before the measure columns. +_ID_COLUMNS: tuple[str, ...] = ("property_id", "landlord_property_id") + @dataclass(frozen=True) class ExportMeasure: @@ -108,14 +111,19 @@ def shape_scenario_sheet( properties: Sequence[PropertyScenarioData], ) -> ExportSheet: """Shape one Scenario's Properties into a wide export sheet (ADR-0065).""" - columns: tuple[str, ...] = ("property_id", "landlord_property_id") + columns: tuple[str, ...] = _ID_COLUMNS + MEASURE_COLUMNS rows: list[dict[str, Any]] = [] for prop in properties: row: dict[str, Any] = { "property_id": prop.property_id, "landlord_property_id": prop.landlord_property_id, } + # Every measure column is present, blank unless this Property has it, so + # all scenario sheets share one contract (ADR-0065). + for column in MEASURE_COLUMNS: + row[column] = "" for measure in prop.measures: - row[measure.measure_type] = measure.estimated_cost + if measure.measure_type in MEASURE_COLUMNS: + row[measure.measure_type] = measure.estimated_cost rows.append(row) return ExportSheet(columns=columns, rows=tuple(rows))