brotherton-erpnext/erpnext/patches/v5_0/update_projects.py

35 lines
1.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import frappe
def execute():
# convert milestones to tasks
frappe.reload_doctype("Project")
2015-04-24 16:07:32 +05:30
frappe.reload_doc("projects", "doctype", "project_task")
frappe.reload_doctype("Task")
2015-05-15 14:44:52 +05:30
frappe.reload_doc("projects", "doctype", "task_depends_on")
frappe.reload_doc("projects", "doctype", "time_log")
for m in frappe.get_all("Project Milestone", "*"):
2015-02-26 20:27:41 +05:30
if (m.milestone and m.milestone_date
and frappe.db.exists("Project", m.parent)):
subject = (m.milestone[:139] + "") if (len(m.milestone) > 140) else m.milestone
description = m.milestone
2015-05-26 16:32:30 +05:30
task = frappe.get_doc({
2015-02-24 13:05:34 +05:30
"doctype": "Task",
"subject": subject,
"description": description if description!=subject else None,
2015-02-24 13:05:34 +05:30
"expected_start_date": m.milestone_date,
"status": "Open" if m.status=="Pending" else "Closed",
"project": m.parent,
2015-05-26 16:32:30 +05:30
})
task.flags.ignore_mandatory = True
task.insert(ignore_permissions=True)
# remove project milestone
frappe.delete_doc("DocType", "Project Milestone")
# remove calendar events for milestone
for e in frappe.get_all("Event", ["name"], {"ref_type": "Project"}):
frappe.delete_doc("Event", e.name)