Skip to content

Commit

Permalink
Merge pull request #42969 from lbrandh/project_completion
Browse files Browse the repository at this point in the history
fix: A project without tasks should be able to complete
  • Loading branch information
ruthra-kumar authored Sep 17, 2024
2 parents d228ac3 + 4eeae80 commit fdd62f7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions erpnext/projects/doctype/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ def on_trash(self):
frappe.db.set_value("Sales Order", {"project": self.name}, "project", "")

def update_percent_complete(self):
if self.status == "Completed":
if (
len(frappe.get_all("Task", dict(project=self.name))) == 0
): # A project without tasks should be able to complete
self.percent_complete_method = "Manual"
self.percent_complete = 100

if self.percent_complete_method == "Manual":
if self.status == "Completed":
self.percent_complete = 100
Expand Down
28 changes: 28 additions & 0 deletions erpnext/projects/doctype/project/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,34 @@ def test_project_with_template_tasks_having_common_name(self):
if not pt.is_group:
self.assertIsNotNone(pt.parent_task)

def test_project_having_no_tasks_complete(self):
project_name = "Test Project - No Tasks Completion"
frappe.db.sql(""" delete from tabTask where project = %s """, project_name)
frappe.delete_doc("Project", project_name)

project = frappe.get_doc(
{
"doctype": "Project",
"project_name": project_name,
"status": "Open",
"expected_start_date": nowdate(),
"company": "_Test Company",
}
).insert()

tasks = frappe.get_all(
"Task",
["subject", "exp_end_date", "depends_on_tasks", "name", "parent_task"],
dict(project=project.name),
order_by="creation asc",
)

self.assertEqual(project.status, "Open")
self.assertEqual(len(tasks), 0)
project.status = "Completed"
project.save()
self.assertEqual(project.status, "Completed")


def get_project(name, template):
project = frappe.get_doc(
Expand Down

0 comments on commit fdd62f7

Please sign in to comment.