brotherton-erpnext/erpnext/patches/v13_0/update_project_template_tasks.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.4 KiB
Python
Raw Normal View History

2020-12-16 13:37:21 +05:30
# Copyright (c) 2019, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
2020-12-16 13:37:21 +05:30
import frappe
2020-12-16 13:37:21 +05:30
def execute():
2021-01-22 11:47:13 +05:30
frappe.reload_doc("projects", "doctype", "project_template")
frappe.reload_doc("projects", "doctype", "project_template_task")
frappe.reload_doc("projects", "doctype", "task")
2021-01-07 15:16:15 +05:30
2021-01-22 11:47:13 +05:30
# Update property setter status if any
2021-01-22 17:12:35 +05:30
property_setter = frappe.db.get_value(
2021-01-22 11:47:13 +05:30
"Property Setter", {"doc_type": "Task", "field_name": "status", "property": "options"}
)
2021-01-11 10:05:54 +05:30
2021-01-22 17:12:35 +05:30
if property_setter:
property_setter_doc = frappe.get_doc(
"Property Setter", {"doc_type": "Task", "field_name": "status", "property": "options"}
)
2021-01-22 11:47:13 +05:30
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,
2022-03-28 18:52:46 +05:30
)
2021-01-22 11:47:13 +05:30
).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()