feat: project template having dependent tasks
This commit is contained in:
parent
6574404536
commit
f9751f1f95
@ -55,11 +55,13 @@ class Project(Document):
|
|||||||
|
|
||||||
# create tasks from template
|
# create tasks from template
|
||||||
project_tasks = []
|
project_tasks = []
|
||||||
|
tmp_task_details = []
|
||||||
for task in template.tasks:
|
for task in template.tasks:
|
||||||
template_task_details = frappe.get_doc("Task", task.task)
|
template_task_details = frappe.get_doc("Task", task.task)
|
||||||
|
tmp_task_details.append(template_task_details)
|
||||||
project_tasks.append(self.create_task_from_template(template_task_details))
|
project_tasks.append(self.create_task_from_template(template_task_details))
|
||||||
|
|
||||||
#self.dependency_mapping(template.tasks, project_tasks)
|
self.dependency_mapping(tmp_task_details, project_tasks)
|
||||||
|
|
||||||
def create_task_from_template(self, task_details):
|
def create_task_from_template(self, task_details):
|
||||||
return frappe.get_doc(dict(
|
return frappe.get_doc(dict(
|
||||||
@ -78,16 +80,33 @@ class Project(Document):
|
|||||||
duration = task_details.duration
|
duration = task_details.duration
|
||||||
)).insert()
|
)).insert()
|
||||||
|
|
||||||
""" def dependency_mapping(self, template_tasks, project_tasks):
|
def dependency_mapping(self, template_tasks, project_tasks):
|
||||||
for tmp_task in template_tasks:
|
for tmp_task in template_tasks:
|
||||||
for prj_task in project_tasks:
|
for prj_task in project_tasks:
|
||||||
if tmp_task.subject == prj_task.subject:
|
if tmp_task.subject == prj_task.subject:
|
||||||
|
self.check_depends_on_value(tmp_task, prj_task, project_tasks)
|
||||||
|
self.check_for_parent_tasks(tmp_task, prj_task, project_tasks)
|
||||||
|
|
||||||
|
def check_depends_on_value(self, tmp_task, prj_task, project_tasks):
|
||||||
if tmp_task.depends_on and not prj_task.depends_on:
|
if tmp_task.depends_on and not prj_task.depends_on:
|
||||||
for child_task in tmp_task.depends_on:
|
for child_task in tmp_task.depends_on:
|
||||||
child_task_detai
|
child_task_subject = frappe.db.get_value("Task", child_task.task, "subject")
|
||||||
prj_task.depends_on = tmp_task.depends_on
|
corresponding_prj_task = list(filter(lambda x: x.subject == child_task_subject, project_tasks))
|
||||||
"""
|
if len(corresponding_prj_task):
|
||||||
|
prj_task.append("depends_on",{
|
||||||
|
"task": corresponding_prj_task[0].name
|
||||||
|
})
|
||||||
|
prj_task.save()
|
||||||
|
|
||||||
|
def check_for_parent_tasks(self, tmp_task, prj_task, project_tasks):
|
||||||
|
if tmp_task.parent_task and not prj_task.parent_task:
|
||||||
|
parent_task_subject = frappe.db.get_value("Task", tmp_task.parent_task, "subject")
|
||||||
|
corresponding_prj_task = list(filter(lambda x: x.subject == parent_task_subject, project_tasks))
|
||||||
|
if len(corresponding_prj_task):
|
||||||
|
prj_task.parent_task = corresponding_prj_task[0].name
|
||||||
|
print(prj_task.name, prj_task.parent_task, corresponding_prj_task[0].name)
|
||||||
|
prj_task.save()
|
||||||
|
print(prj_task.name, corresponding_prj_task[0].name)
|
||||||
|
|
||||||
def is_row_updated(self, row, existing_task_data, fields):
|
def is_row_updated(self, row, existing_task_data, fields):
|
||||||
if self.get("__islocal") or not existing_task_data: return True
|
if self.get("__islocal") or not existing_task_data: return True
|
||||||
|
@ -3,8 +3,27 @@
|
|||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
# import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe import _
|
||||||
|
|
||||||
class ProjectTemplate(Document):
|
class ProjectTemplate(Document):
|
||||||
pass
|
|
||||||
|
def validate(self):
|
||||||
|
self.validate_dependencies()
|
||||||
|
|
||||||
|
def validate_dependencies(self):
|
||||||
|
for task in self.tasks:
|
||||||
|
task_details = frappe.get_doc("Task", task.task)
|
||||||
|
if task_details.depends_on:
|
||||||
|
for dependency_task in task_details.depends_on:
|
||||||
|
if not self.check_dependent_task_presence(dependency_task.task):
|
||||||
|
task_details_format = """<a href="#Form/Task/{0}">{0}</a>""".format(task_details.name)
|
||||||
|
dependency_task_format = """<a href="#Form/Task/{0}">{0}</a>""".format(dependency_task.task)
|
||||||
|
frappe.throw(_("Task {0} depends on Task {1}. Please add Task {1} to the Tasks list.").format(frappe.bold(task_details_format), frappe.bold(dependency_task_format)))
|
||||||
|
|
||||||
|
def check_dependent_task_presence(self, task):
|
||||||
|
for task_details in self.tasks:
|
||||||
|
if task_details.task == task:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
@ -34,6 +34,7 @@ class Task(NestedSet):
|
|||||||
self.validate_progress()
|
self.validate_progress()
|
||||||
self.validate_status()
|
self.validate_status()
|
||||||
self.update_depends_on()
|
self.update_depends_on()
|
||||||
|
self.validate_dependencies_for_template_task()
|
||||||
|
|
||||||
def validate_dates(self):
|
def validate_dates(self):
|
||||||
if self.exp_start_date and self.exp_end_date and getdate(self.exp_start_date) > getdate(self.exp_end_date):
|
if self.exp_start_date and self.exp_end_date and getdate(self.exp_start_date) > getdate(self.exp_end_date):
|
||||||
@ -72,6 +73,24 @@ class Task(NestedSet):
|
|||||||
if self.status == 'Completed':
|
if self.status == 'Completed':
|
||||||
self.progress = 100
|
self.progress = 100
|
||||||
|
|
||||||
|
def validate_dependencies_for_template_task(self):
|
||||||
|
if self.is_template:
|
||||||
|
self.validate_parent_template_task()
|
||||||
|
self.validate_depends_on_tasks()
|
||||||
|
|
||||||
|
def validate_parent_template_task(self):
|
||||||
|
if self.parent_task:
|
||||||
|
if not frappe.db.get_value("Task", self.parent_task, "is_template"):
|
||||||
|
parent_task_format = """<a href="#Form/Task/{0}">{0}</a>""".format(self.parent_task)
|
||||||
|
frappe.throw(_("Parent Task {0} is not a Template Task").format(parent_task_format))
|
||||||
|
|
||||||
|
def validate_depends_on_tasks(self):
|
||||||
|
if self.depends_on:
|
||||||
|
for task in self.depends_on:
|
||||||
|
if not frappe.db.get_value("Task", task.task, "is_template"):
|
||||||
|
dependent_task_format = """<a href="#Form/Task/{0}">{0}</a>""".format(task.task)
|
||||||
|
frappe.throw(_("Dependent Task {0} is not a Template Task").format(dependent_task_format))
|
||||||
|
|
||||||
def update_depends_on(self):
|
def update_depends_on(self):
|
||||||
depends_on_tasks = self.depends_on_tasks or ""
|
depends_on_tasks = self.depends_on_tasks or ""
|
||||||
for d in self.depends_on:
|
for d in self.depends_on:
|
||||||
|
Loading…
Reference in New Issue
Block a user