2020-12-16 08:07:21 +00:00
|
|
|
# Copyright (c) 2019, Frappe and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2020-12-16 08:07:21 +00:00
|
|
|
import frappe
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2020-12-16 08:07:21 +00:00
|
|
|
def execute():
|
2021-01-22 06:17:13 +00:00
|
|
|
frappe.reload_doc("projects", "doctype", "project_template")
|
|
|
|
frappe.reload_doc("projects", "doctype", "project_template_task")
|
|
|
|
frappe.reload_doc("projects", "doctype", "task")
|
2021-01-07 09:46:15 +00:00
|
|
|
|
2021-01-22 06:17:13 +00:00
|
|
|
# Update property setter status if any
|
2021-01-22 11:42:35 +00:00
|
|
|
property_setter = frappe.db.get_value('Property Setter', {'doc_type': 'Task',
|
2021-01-22 06:17:13 +00:00
|
|
|
'field_name': 'status', 'property': 'options'})
|
2021-01-11 04:35:54 +00:00
|
|
|
|
2021-01-22 11:42:35 +00:00
|
|
|
if property_setter:
|
|
|
|
property_setter_doc = frappe.get_doc('Property Setter', {'doc_type': 'Task',
|
|
|
|
'field_name': 'status', 'property': 'options'})
|
2021-01-22 06:17:13 +00:00
|
|
|
property_setter_doc.value += "\nTemplate"
|
|
|
|
property_setter_doc.save()
|
|
|
|
|
|
|
|
for template_name in frappe.get_all('Project Template'):
|
|
|
|
template = frappe.get_doc("Project Template", template_name.name)
|
|
|
|
replace_tasks = False
|
|
|
|
new_tasks = []
|
|
|
|
for task in template.tasks:
|
|
|
|
if task.subject:
|
|
|
|
replace_tasks = True
|
|
|
|
new_task = frappe.get_doc(dict(
|
|
|
|
doctype = "Task",
|
|
|
|
subject = task.subject,
|
|
|
|
start = task.start,
|
|
|
|
duration = task.duration,
|
|
|
|
task_weight = task.task_weight,
|
|
|
|
description = task.description,
|
|
|
|
is_template = 1
|
|
|
|
)).insert()
|
|
|
|
new_tasks.append(new_task)
|
|
|
|
|
|
|
|
if replace_tasks:
|
|
|
|
template.tasks = []
|
|
|
|
for tsk in new_tasks:
|
|
|
|
template.append("tasks", {
|
|
|
|
"task": tsk.name,
|
|
|
|
"subject": tsk.subject
|
|
|
|
})
|
|
|
|
template.save()
|