Merge pull request #16288 from Anurag810/task-fixes
[fix] 'Expected End Date' in task should not be later than 'Expected End Date' of project
diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py
index 649d73a..371fc5c 100755
--- a/erpnext/projects/doctype/task/task.py
+++ b/erpnext/projects/doctype/task/task.py
@@ -12,6 +12,7 @@
class CircularReferenceError(frappe.ValidationError): pass
+class EndDateCannotBeGreaterThanProjectEndDateError(frappe.ValidationError): pass
class Task(NestedSet):
nsm_parent_field = 'parent_task'
@@ -43,6 +44,12 @@
if self.act_start_date and self.act_end_date and getdate(self.act_start_date) > getdate(self.act_end_date):
frappe.throw(_("'Actual Start Date' can not be greater than 'Actual End Date'"))
+ if(self.project):
+ if frappe.db.exists("Project", self.project):
+ expected_end_date = frappe.db.get_value("Project", self.project, "expected_end_date")
+ if self.exp_end_date and expected_end_date and getdate(self.exp_end_date) > getdate(expected_end_date) :
+ frappe.throw(_("Expected end date cannot be after Project: <b>'{0}'</b> Expected end date").format(self.project), EndDateCannotBeGreaterThanProjectEndDateError)
+
def validate_status(self):
if self.status!=self.get_db_value("status") and self.status == "Closed":
for d in self.depends_on:
diff --git a/erpnext/projects/doctype/task/test_task.py b/erpnext/projects/doctype/task/test_task.py
index 0966b76..6fb5412 100644
--- a/erpnext/projects/doctype/task/test_task.py
+++ b/erpnext/projects/doctype/task/test_task.py
@@ -5,11 +5,11 @@
import unittest
from frappe.utils import getdate, nowdate, add_days
-from erpnext.projects.doctype.task.task import CircularReferenceError
+from erpnext.projects.doctype.task.task import CircularReferenceError, EndDateCannotBeGreaterThanProjectEndDateError
class TestTask(unittest.TestCase):
def test_circular_reference(self):
- task1 = create_task("_Test Task 1", nowdate(), add_days(nowdate(), 10))
+ task1 = create_task("_Test Task 1", add_days(nowdate(), -15), add_days(nowdate(), -10))
task2 = create_task("_Test Task 2", add_days(nowdate(), 11), add_days(nowdate(), 15), task1.name)
task3 = create_task("_Test Task 3", add_days(nowdate(), 11), add_days(nowdate(), 15), task2.name)
@@ -97,7 +97,16 @@
self.assertEqual(frappe.db.get_value("Task", task.name, "status"), "Overdue")
-def create_task(subject, start=None, end=None, depends_on=None, project=None):
+ def test_end_date_validation(self):
+ task_end = create_task("Testing_Enddate_validation", add_days(nowdate(), 35), add_days(nowdate(), 45), save=False)
+ pro = frappe.get_doc("Project", task_end.project)
+ pro.expected_end_date = add_days(nowdate(), 40)
+ pro.save()
+ self.assertRaises(EndDateCannotBeGreaterThanProjectEndDateError, task_end.save)
+
+
+
+def create_task(subject, start=None, end=None, depends_on=None, project=None, save=True):
if not frappe.db.exists("Task", subject):
task = frappe.new_doc('Task')
task.status = "Open"
@@ -105,7 +114,8 @@
task.exp_start_date = start or nowdate()
task.exp_end_date = end or nowdate()
task.project = project or "_Test Project"
- task.save()
+ if save:
+ task.save()
else:
task = frappe.get_doc("Task", subject)
@@ -113,6 +123,7 @@
task.append("depends_on", {
"task": depends_on
})
- task.save()
+ if save:
+ task.save()
return task
\ No newline at end of file