diff --git a/erpnext/projects/doctype/project/project.json b/erpnext/projects/doctype/project/project.json index 4490b61c74..62210b80c3 100644 --- a/erpnext/projects/doctype/project/project.json +++ b/erpnext/projects/doctype/project/project.json @@ -131,7 +131,7 @@ "options": "Project Task", "permlevel": 0, "precision": "", - "reqd": 0 + "reqd": 1 }, { "fieldname": "percent_complete", @@ -279,7 +279,7 @@ "icon": "icon-puzzle-piece", "idx": 1, "max_attachments": 4, - "modified": "2015-03-31 06:12:03.372091", + "modified": "2015-04-10 05:11:18.849171", "modified_by": "Administrator", "module": "Projects", "name": "Project", diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index 1fc327f16b..b481ee422a 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -35,17 +35,12 @@ class Project(Document): def validate(self): self.validate_dates() - self.validate_tasks() self.sync_tasks() def validate_dates(self): if self.project_start_date and self.completion_date: if getdate(self.completion_date) < getdate(self.project_start_date): frappe.throw(_("Expected Completion Date can not be less than Project Start Date")) - - def validate_tasks(self): - if not self.tasks: - frappe.throw("Task is mandatory against a project") def sync_tasks(self): """sync tasks and remove table""" @@ -74,8 +69,6 @@ class Project(Document): for t in frappe.get_all("Task", ["name"], {"project": self.name, "name": ("not in", task_names)}): frappe.delete_doc("Task", t.name) - self.tasks = [] - def update_percent_complete(self): total = frappe.db.sql("""select count(*) from tabTask where project=%s""", self.name)[0][0] @@ -85,7 +78,6 @@ class Project(Document): frappe.db.set_value("Project", self.name, "percent_complete", int(float(completed) / total * 100)) - @frappe.whitelist() def get_cost_center_name(project_name): return frappe.db.get_value("Project", project_name, "cost_center") diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py index fdd225d77a..617809954d 100644 --- a/erpnext/projects/doctype/task/task.py +++ b/erpnext/projects/doctype/task/task.py @@ -61,14 +61,11 @@ class Task(Document): self.act_end_date= tl.end_date def update_project(self): - if self.project: - total_activity_cost = frappe.db.sql("""select sum(actual_cost) from `tabTask` - where project = %s""",self.project) - frappe.db.set_value("Project", self.project, "total_activity_cost", total_activity_cost) - - total_expense_claim = frappe.db.sql("""select sum(total_expense_claim) from `tabTask` - where project = %s""",self.project) - frappe.db.set_value("Project", self.project, "total_expense_claim", total_expense_claim) + if self.project and frappe.db.exists("Project", self.project): + total_cost = frappe.db.sql("""select sum(actual_cost) as actual_cost, sum(total_expense_claim) as expense_claim + from `tabTask` where project = %s""", self.project, as_dict=1)[0] + frappe.db.set_value("Project", self.project, "total_activity_cost", total_cost.actual_cost) + frappe.db.set_value("Project", self.project, "total_expense_claim", total_cost.expense_claim) @frappe.whitelist() def get_events(start, end, filters=None):