mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-27 23:35:01 +00:00
Resolve Effective-EPC fields by override then lodged then predicted 🟥
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6ea3f31d82
commit
642789db01
1 changed files with 63 additions and 0 deletions
|
|
@ -317,3 +317,66 @@ def test_effective_epc_descriptive_fields_come_from_the_lodged_epc(
|
|||
assert row.current_sap_points == 58
|
||||
assert row.lodgement_date == "2005-01-01"
|
||||
assert row.is_expired is True
|
||||
|
||||
|
||||
def test_property_type_override_beats_the_lodged_epc(db_engine: Engine) -> None:
|
||||
# arrange — the lodged EPC says Flat, but a landlord override says House
|
||||
# (Effective-EPC precedence: override → lodged, ADR-0065).
|
||||
with Session(db_engine) as session:
|
||||
session.add(PropertyRow(id=1, portfolio_id=100, landlord_property_id="LP1"))
|
||||
session.add(
|
||||
PlanModel(portfolio_id=100, property_id=1, scenario_id=5, is_default=True)
|
||||
)
|
||||
_add_epc(session, property_id=1, epc_id=1, source="lodged", property_type="Flat")
|
||||
session.add(
|
||||
PropertyOverrideRow(
|
||||
property_id=1,
|
||||
portfolio_id=100,
|
||||
building_part=0,
|
||||
override_component="property_type",
|
||||
override_value="House",
|
||||
original_spreadsheet_description="detached house",
|
||||
)
|
||||
)
|
||||
session.commit()
|
||||
|
||||
# act
|
||||
with Session(db_engine) as session:
|
||||
rows = ScenarioExportPostgresRepository(session).rows_for(
|
||||
portfolio_id=100, scenario_id=5, property_ids=[1]
|
||||
)
|
||||
|
||||
# assert — the override wins.
|
||||
assert rows[0].property_type == "House"
|
||||
|
||||
|
||||
def test_falls_back_to_the_predicted_epc_when_there_is_no_lodged_epc(
|
||||
db_engine: Engine,
|
||||
) -> None:
|
||||
# arrange — the Property has only a predicted EPC slot, no lodged cert.
|
||||
with Session(db_engine) as session:
|
||||
session.add(PropertyRow(id=1, portfolio_id=100, landlord_property_id="LP1"))
|
||||
session.add(
|
||||
PlanModel(portfolio_id=100, property_id=1, scenario_id=5, is_default=True)
|
||||
)
|
||||
_add_epc(
|
||||
session,
|
||||
property_id=1,
|
||||
epc_id=1,
|
||||
source="predicted",
|
||||
property_type="Bungalow",
|
||||
elements={"wall": "Predicted solid brick wall"},
|
||||
)
|
||||
session.commit()
|
||||
|
||||
# act
|
||||
with Session(db_engine) as session:
|
||||
rows = ScenarioExportPostgresRepository(session).rows_for(
|
||||
portfolio_id=100, scenario_id=5, property_ids=[1]
|
||||
)
|
||||
|
||||
# assert — the predicted slot supplies the descriptive picture (precedence
|
||||
# falls through to predicted when no lodged EPC exists).
|
||||
row = rows[0]
|
||||
assert row.property_type == "Bungalow"
|
||||
assert row.walls == "Predicted solid brick wall"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue