diff --git a/backend/app/db/functions/recommendations_functions.py b/backend/app/db/functions/recommendations_functions.py index 7ff09f22..b03909ee 100644 --- a/backend/app/db/functions/recommendations_functions.py +++ b/backend/app/db/functions/recommendations_functions.py @@ -33,6 +33,12 @@ def create_scenario(session: Session, scenario): :param scenario: dictionary of data representing a scenario to be created """ try: + + # Before creating a new scenario, we check if there is a scenario for this portfolio id already + # If there is, it means that any new scnario created will NOT be the default scenario + existing_scenario = session.query(Scenario).filter_by(portfolio_id=scenario["portfolio_id"]).first() + scenario["is_default"] = True if not existing_scenario else False + new_scenario = Scenario(**scenario) session.add(new_scenario) session.flush() diff --git a/backend/app/db/models/recommendations.py b/backend/app/db/models/recommendations.py index ed3f326e..a1743436 100644 --- a/backend/app/db/models/recommendations.py +++ b/backend/app/db/models/recommendations.py @@ -85,6 +85,7 @@ class Scenario(Base): non_invasive_recommendations_file_path = Column(String) exclusions = Column(String) multi_plan = Column(Boolean, default=False) + is_default = Column(Boolean, default=False, nullable=False) # Add in the fields we need, which were previously sitting at the portfolio level cost = Column(Float) @@ -107,3 +108,5 @@ class Scenario(Base): cost_per_co2_saved = Column(String) cost_per_sap_point = Column(String) valuation_return_on_investment = Column(String) + property_valuation_increase = Column(Float) + labour_days = Column(Float)