A property's first plan becomes its default whatever the scenario says 🟩

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-07 16:13:47 +00:00
parent 101c1f1f21
commit 0eaf6fa99c

View file

@ -205,13 +205,21 @@ def _flush_writes(engine: Engine, writes: list[_PropertyWrite]) -> None:
uow.epc.save_batch(lodged_requests)
if predicted_requests:
uow.epc.save_batch(predicted_requests)
# First plan wins: a property with no default Plan yet gets this Plan
# as its default whatever the Scenario's flag says (the legacy
# p.is_new rule — readers select one default Plan per property, so a
# first run under a non-default Scenario must still produce one).
# Also heals properties left default-less by runs before this rule.
have_default: set[int] = uow.plan.property_ids_with_default_plans(
[w.property_id for w in writes]
)
plan_requests = [
PlanSaveRequest(
w.plan,
property_id=w.property_id,
scenario_id=w.scenario_id,
portfolio_id=w.portfolio_id,
is_default=w.is_default,
is_default=w.is_default or w.property_id not in have_default,
)
for w in writes
]