@Amalendu
Project Task is not stored in Project Task table. Project Task only saved in Task table.
When one load Project, All task is fetched related to that project using get_task() and appended to project_task child table.
from frappe.utils import flt, getdate, get_url, now
from frappe import _
from frappe.model.document import Document
from erpnext.controllers.queries import get_filters_cond
from frappe.desk.reportview import get_match_cond
import datetime
from six import iteritems
class Project(Document):
def get_feed(self):
return '{0}: {1}'.format(_(self.status), self.project_name)
def onload(self):
"""Load project tasks for quick view"""
if not self.get('__unsaved') and not self.get("tasks"):
self.load_tasks()
self.set_onload('activity_summary', frappe.db.sql('''select activity_type,
When you save project, sync_task() is used to update or create task.
task_map = {
"title": task.subject,
"status": task.status,
"start_date": task.exp_start_date,
"end_date": task.exp_end_date,
"description": task.description,
"task_id": task.name,
"task_weight": task.task_weight
}
self.map_custom_fields(task, task_map)
self.append("tasks", task_map)
def get_tasks(self):
if self.name is None:
return {}
else:
return frappe.get_all("Task", "*", {"project": self.name}, order_by="exp_start_date asc")
def validate(self):
& here is important thing, after sync and before save, all project task is cleared, so task will never stored into project_task child table
def __setup__(self):
self.onload()
def load_tasks(self):
"""Load `tasks` from the database"""
self.tasks = []
for task in self.get_tasks():
task_map = {
"title": task.subject,
"status": task.status,
"start_date": task.exp_start_date,
"end_date": task.exp_end_date,
"description": task.description,
"task_id": task.name,
"task_weight": task.task_weight
}
self.map_custom_fields(task, task_map)
self.append("tasks", task_map)