diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index 3b42f6a69d..e3fd1a8622 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -66,11 +66,11 @@ class Project(Document): def validate(self): self.validate_project_name() - self.validate_dates() self.validate_weights() self.sync_tasks() self.tasks = [] self.load_tasks() + self.validate_dates() self.send_welcome_email() self.update_percent_complete() @@ -79,6 +79,24 @@ class Project(Document): frappe.throw(_("Project {0} already exists").format(frappe.safe_decode(self.project_name))) def validate_dates(self): + if self.tasks: + for d in self.tasks: + if self.expected_start_date: + if d.start_date and getdate(d.start_date) < getdate(self.expected_start_date): + frappe.throw(_("Start date of task {0} cannot be less than {1} expected start date {2}") + .format(d.title, self.name, self.expected_start_date)) + if d.end_date and getdate(d.end_date) < getdate(self.expected_start_date): + frappe.throw(_("End date of task {0} cannot be less than {1} expected start date {2}") + .format(d.title, self.name, self.expected_start_date)) + + if self.expected_end_date: + if d.start_date and getdate(d.start_date) > getdate(self.expected_end_date): + frappe.throw(_("Start date of task {0} cannot be greater than {1} expected end date {2}") + .format(d.title, self.name, self.expected_end_date)) + if d.end_date and getdate(d.end_date) > getdate(self.expected_end_date): + frappe.throw(_("End date of task {0} cannot be greater than {1} expected end date {2}") + .format(d.title, self.name, self.expected_end_date)) + if self.expected_start_date and self.expected_end_date: if getdate(self.expected_end_date) < getdate(self.expected_start_date): frappe.throw(_("Expected End Date can not be less than Expected Start Date")) diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py index 371fc5c79b..fffa9c1657 100755 --- a/erpnext/projects/doctype/task/task.py +++ b/erpnext/projects/doctype/task/task.py @@ -44,12 +44,6 @@ class Task(NestedSet): 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: '{0}' 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 6fb5412473..9971946cb4 100644 --- a/erpnext/projects/doctype/task/test_task.py +++ b/erpnext/projects/doctype/task/test_task.py @@ -5,7 +5,7 @@ import frappe import unittest from frappe.utils import getdate, nowdate, add_days -from erpnext.projects.doctype.task.task import CircularReferenceError, EndDateCannotBeGreaterThanProjectEndDateError +from erpnext.projects.doctype.task.task import CircularReferenceError class TestTask(unittest.TestCase): def test_circular_reference(self): @@ -97,15 +97,6 @@ class TestTask(unittest.TestCase): self.assertEqual(frappe.db.get_value("Task", task.name, "status"), "Overdue") - 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')