Skip to content

Commit 299341c

Browse files
KAAV-3492 refactored code
1 parent c941004 commit 299341c

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

projects/models/project.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -934,21 +934,21 @@ def get_preview_deadlines(self, updated_attributes, subtype, confirmed_fields=No
934934

935935
# UX80.4.2.3.7: When adding element row, update phase boundaries
936936
# so cascade calculates from the correct snapped position
937-
if "_paattyy" in identifier:
938-
# Map identifier patterns to phase boundary pairs
939-
PHASE_BOUNDARY_MAP = {
940-
"oas": ("oasvaihe_paattyy_pvm", "ehdotusvaihe_alkaa_pvm"),
941-
"periaatteet": ("periaatteetvaihe_paattyy_pvm", "oasvaihe_alkaa_pvm"),
942-
"luonnos": ("luonnosvaihe_paattyy_pvm", "ehdotusvaihe_alkaa_pvm"),
943-
}
944-
# Special case: ehdotus but not tarkistettu
945-
if "ehdotus" in identifier and "tarkistettu" not in identifier:
946-
boundaries = ("ehdotusvaihe_paattyy_pvm", "tarkistettuehdotusvaihe_alkaa_pvm")
947-
else:
948-
boundaries = next((v for k, v in PHASE_BOUNDARY_MAP.items() if k in identifier), None)
937+
if "_paattyy" in identifier and dl.phase:
938+
# Derive phase boundary identifiers dynamically from phase name
939+
phase_name = dl.phase.common_project_phase.name.lower().replace(" ", "")
940+
phase_end_id = f"{phase_name}vaihe_paattyy_pvm"
949941

950-
if boundaries:
951-
phase_end_id, next_phase_start_id = boundaries
942+
# Get next phase by index order
943+
next_phase = ProjectPhase.objects.filter(
944+
project_subtype=dl.phase.project_subtype,
945+
index__gt=dl.phase.index
946+
).order_by('index').first()
947+
948+
if next_phase:
949+
next_name = next_phase.common_project_phase.name.lower().replace(" ", "")
950+
next_phase_start_id = f"{next_name}vaihe_alkaa_pvm"
951+
952952
current_phase_end = self._coerce_date_value(updated_attribute_data.get(phase_end_id))
953953
if current_phase_end and max_target != current_phase_end:
954954
log.info(f"[KAAV-3492 BACKEND] Updating phase boundary {phase_end_id} to {max_target}")

0 commit comments

Comments
 (0)