Skip to content

Commit

Permalink
fix: incorrect Parent Task getting set for 2nd to nth child Task (#…
Browse files Browse the repository at this point in the history
…37230)

(cherry picked from commit 73fc974)
  • Loading branch information
s-aga-r authored and mergify[bot] committed Sep 26, 2023
1 parent ba45299 commit dbb40a1
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions erpnext/projects/doctype/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def copy_from_template(self):
tmp_task_details.append(template_task_details)
task = self.create_task_from_template(template_task_details)
project_tasks.append(task)

self.dependency_mapping(tmp_task_details, project_tasks)

def create_task_from_template(self, task_details):
Expand Down Expand Up @@ -105,36 +106,28 @@ def update_if_holiday(self, date):

def dependency_mapping(self, template_tasks, project_tasks):
for project_task in project_tasks:
if project_task.get("template_task"):
template_task = frappe.get_doc("Task", project_task.template_task)
else:
template_task = list(filter(lambda x: x.subject == project_task.subject, template_tasks))[0]
template_task = frappe.get_doc("Task", template_task.name)
template_task = frappe.get_doc("Task", project_task.template_task)

self.check_depends_on_value(template_task, project_task, project_tasks)
self.check_for_parent_tasks(template_task, project_task, project_tasks)

def check_depends_on_value(self, template_task, project_task, project_tasks):
if template_task.get("depends_on") and not project_task.get("depends_on"):
project_template_map = {pt.template_task: pt for pt in project_tasks}

for child_task in template_task.get("depends_on"):
child_task_subject = frappe.db.get_value("Task", child_task.task, "subject")
corresponding_project_task = list(
filter(lambda x: x.subject == child_task_subject, project_tasks)
)
if len(corresponding_project_task):
if project_template_map and project_template_map.get(child_task.task):
project_task.reload() # reload, as it might have been updated in the previous iteration
project_task.append("depends_on", {"task": corresponding_project_task[0].name})
project_task.append("depends_on", {"task": project_template_map.get(child_task.task).name})
project_task.save()

def check_for_parent_tasks(self, template_task, project_task, project_tasks):
if template_task.get("parent_task") and not project_task.get("parent_task"):
parent_task_subject = frappe.db.get_value("Task", template_task.get("parent_task"), "subject")
corresponding_project_task = list(
filter(lambda x: x.subject == parent_task_subject, project_tasks)
)
if len(corresponding_project_task):
project_task.parent_task = corresponding_project_task[0].name
project_task.save()
for pt in project_tasks:
if pt.template_task == template_task.parent_task:
project_task.parent_task = pt.name
project_task.save()
break

def is_row_updated(self, row, existing_task_data, fields):
if self.get("__islocal") or not existing_task_data:
Expand Down

0 comments on commit dbb40a1

Please sign in to comment.