util.get_work_schedule_tasks - fix critical bug with missing root tasks

Now we also use generator to mirror get_schedule_cost_items
This commit is contained in:
Andrej730
2025-07-24 19:14:22 +05:00
parent a99bfd9294
commit f5b28c0df8
@@ -21,7 +21,7 @@ import ifcopenshell.util.date
from math import floor from math import floor
from functools import cache from functools import cache
from typing import Union, Literal, Optional from typing import Union, Literal, Optional
from collections.abc import Iterator from collections.abc import Generator
DURATION_TYPE = Literal["ELAPSEDTIME", "WORKTIME", "NOTDEFINED"] DURATION_TYPE = Literal["ELAPSEDTIME", "WORKTIME", "NOTDEFINED"]
@@ -289,18 +289,17 @@ def get_parent_task(task: ifcopenshell.entity_instance) -> Union[ifcopenshell.en
return obj return obj
def get_all_nested_tasks(task: ifcopenshell.entity_instance) -> Iterator[ifcopenshell.entity_instance]: def get_all_nested_tasks(task: ifcopenshell.entity_instance) -> Generator[ifcopenshell.entity_instance]:
for nested_task in get_nested_tasks(task): for nested_task in get_nested_tasks(task):
yield nested_task yield nested_task
yield from get_all_nested_tasks(nested_task) yield from get_all_nested_tasks(nested_task)
def get_work_schedule_tasks(work_schedule: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]: def get_work_schedule_tasks(work_schedule: ifcopenshell.entity_instance) -> Generator[ifcopenshell.entity_instance]:
tasks = [] """Get all work schedule tasks, including the nested ones."""
for root_task in get_root_tasks(work_schedule): for root_task in get_root_tasks(work_schedule):
nested_tasks = get_all_nested_tasks(root_task) yield root_task
tasks.extend(nested_tasks) yield from get_all_nested_tasks(root_task)
return tasks
def get_root_tasks(work_schedule: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]: def get_root_tasks(work_schedule: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]: