+
+ def walk_process_steps(id_: int,
+ process_step_nodes: list[ProcessStepsNode],
+ steps_nodes: list[TodoStepsNode]) -> None:
+ for process_step_node in process_step_nodes:
+ id_ += 1
+ node = TodoStepsNode(id_, None, process_step_node.process, [])
+ steps_nodes += [node]
+ walk_process_steps(id_, list(process_step_node.steps.values()),
+ node.children)
+
+ def walk_todo_steps(id_: int, todos: list[Todo],
+ steps_nodes: list[TodoStepsNode]) -> None:
+ for todo in todos:
+ matched = False
+ for match in [item for item in steps_nodes
+ if item.process
+ and item.process == todo.process]:
+ match.todo = todo
+ matched = True
+ for child in match.children:
+ child.fillable = True
+ walk_todo_steps(id_, todo.children, match.children)
+ if not matched:
+ id_ += 1
+ node = TodoStepsNode(id_, todo, None, [])
+ steps_nodes += [node]
+ walk_todo_steps(id_, todo.children, node.children)
+
+ def collect_adoptables_keys(steps_nodes: list[TodoStepsNode]
+ ) -> set[int]:
+ ids = set()
+ for node in steps_nodes:
+ if not node.todo:
+ assert isinstance(node.process, Process)
+ assert isinstance(node.process.id_, int)
+ ids.add(node.process.id_)
+ ids = ids | collect_adoptables_keys(node.children)
+ return ids
+