X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=plomtask%2Ftodos.py;h=ed78ca947b359286456e7dcc4c664fcb32961c12;hb=e825a876e82ffbedf0234f4dfb6d6055d9e29241;hp=ff6cdcb1e96144743f828ca5fea14072988be10a;hpb=a7adce16f1969400cb988ff900f504157e454cce;p=plomtask diff --git a/plomtask/todos.py b/plomtask/todos.py index ff6cdcb..ed78ca9 100644 --- a/plomtask/todos.py +++ b/plomtask/todos.py @@ -39,9 +39,9 @@ class Todo(BaseModel, ConditionsRelations): self.enables: list[Condition] = [] self.disables: list[Condition] = [] if not self.id_: - self.conditions = process.conditions[:] - self.enables = process.enables[:] - self.disables = process.disables[:] + self.conditions = self.process.conditions[:] + self.enables = self.process.enables[:] + self.disables = self.process.disables[:] @classmethod def from_table_row(cls, db_conn: DatabaseConnection, @@ -127,6 +127,17 @@ class Todo(BaseModel, ConditionsRelations): """Return ID of tasked Process.""" return self.process.id_ + @property + def unsatisfied_dependencies(self) -> list[int]: + """Return Process IDs of .process.explicit_steps not in .children.""" + child_process_ids = {c.process.id_ for c in self.children} + unsatisfied: list[int] = [] + for process_id in [s.step_process_id + for s in self.process.explicit_steps]: + if process_id not in child_process_ids: + unsatisfied += [process_id] + return unsatisfied + @property def is_done(self) -> bool: """Wrapper around self._is_done so we can control its setter.""" @@ -144,6 +155,13 @@ class Todo(BaseModel, ConditionsRelations): for condition in self.disables: condition.is_active = False + def adopt_from(self, todos: list[Todo]) -> None: + """As far as possible, fill unsatisfied dependencies from todos.""" + for process_id in self.unsatisfied_dependencies: + for todo in [t for t in todos if t.process.id_ == process_id]: + self.add_child(todo) + break + def get_step_tree(self, seen_todos: set[int], seen_conditions: set[int]) -> TodoStepsNode: """Return tree of depended-on Todos and Conditions."""