fix: get_doc to avoid modified error

This commit is contained in:
pateljannat 2020-12-22 11:56:59 +05:30
parent 9466e42e70
commit 3a26f26671
2 changed files with 19 additions and 18 deletions

View File

@ -81,27 +81,28 @@ class Project(Document):
def dependency_mapping(self, template_tasks, project_tasks):
for template_task in template_tasks:
project_task = list(filter(lambda x: x.subject == template_task.subject, project_tasks))[0]
if template_task.get("depends_on") and not project_task.get("depends_on"):
self.check_depends_on_value(template_task, project_task, project_tasks)
if template_task.get("parent_task") and not project_task.get("parent_task"):
self.check_for_parent_tasks(template_task, project_task, project_tasks)
project_task = frappe.get_doc("Task", project_task.name)
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):
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):
project_task.append("depends_on",{
"task": corresponding_project_task[0].name
})
project_task.save()
if template_task.get("depends_on") and not project_task.get("depends_on"):
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):
project_task.append("depends_on",{
"task": corresponding_project_task[0].name
})
project_task.save()
def check_for_parent_tasks(self, template_task, project_task, project_tasks):
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()
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()
def is_row_updated(self, row, existing_task_data, fields):
if self.get("__islocal") or not existing_task_data: return True

View File

@ -52,7 +52,7 @@ class TestProject(unittest.TestCase):
template = make_project_template("Test Project Template - Tasks with Parent-Child Relation", [task1, task2, task3])
project = get_project(project_name, template)
tasks = frappe.get_all('Task', ['subject','exp_end_date','depends_on_tasks', 'name'], dict(project=project.name), order_by='creation asc')
tasks = frappe.get_all('Task', ['subject','exp_end_date','depends_on_tasks', 'name', 'parent_task'], dict(project=project.name), order_by='creation asc')
self.assertEqual(tasks[0].subject, 'Test Template Task Parent')
self.assertEqual(getdate(tasks[0].exp_end_date), calculate_end_date(project, 1, 1))