Test case
This commit is contained in:
parent
3637e14e9f
commit
a3b5f5f6e4
@ -12,6 +12,7 @@ from frappe.utils.nestedset import NestedSet
|
|||||||
|
|
||||||
|
|
||||||
class CircularReferenceError(frappe.ValidationError): pass
|
class CircularReferenceError(frappe.ValidationError): pass
|
||||||
|
class EndDateConnotGreaterThanProjecteEndDateError(frappe.ValidationError): pass
|
||||||
|
|
||||||
class Task(NestedSet):
|
class Task(NestedSet):
|
||||||
nsm_parent_field = 'parent_task'
|
nsm_parent_field = 'parent_task'
|
||||||
@ -43,9 +44,10 @@ class Task(NestedSet):
|
|||||||
if self.act_start_date and self.act_end_date and getdate(self.act_start_date) > getdate(self.act_end_date):
|
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'"))
|
frappe.throw(_("'Actual Start Date' can not be greater than 'Actual End Date'"))
|
||||||
|
|
||||||
doc = frappe.get_doc("Project",self.project)
|
doc = frappe.get_doc("Project", self.project)
|
||||||
if self.exp_end_date and doc.expected_end_date and getdate(self.exp_end_date) > getdate(doc.expected_end_date) :
|
if self.exp_end_date and doc.expected_end_date and getdate(self.exp_end_date) > getdate(doc.expected_end_date) :
|
||||||
frappe.throw(_("Expected end date cannot be after Project: "+doc.name+" Expected end date"))
|
frappe.msgprint(_("Expected end date cannot be after Project: <b>'{0}'</b> Expected end date").format(doc.name))
|
||||||
|
raise EndDateConnotGreaterThanProjecteEndDateError
|
||||||
|
|
||||||
def validate_status(self):
|
def validate_status(self):
|
||||||
if self.status!=self.get_db_value("status") and self.status == "Closed":
|
if self.status!=self.get_db_value("status") and self.status == "Closed":
|
||||||
|
@ -5,7 +5,7 @@ import frappe
|
|||||||
import unittest
|
import unittest
|
||||||
from frappe.utils import getdate, nowdate, add_days
|
from frappe.utils import getdate, nowdate, add_days
|
||||||
|
|
||||||
from erpnext.projects.doctype.task.task import CircularReferenceError
|
from erpnext.projects.doctype.task.task import CircularReferenceError, EndDateConnotGreaterThanProjecteEndDateError
|
||||||
|
|
||||||
class TestTask(unittest.TestCase):
|
class TestTask(unittest.TestCase):
|
||||||
def test_circular_reference(self):
|
def test_circular_reference(self):
|
||||||
@ -97,7 +97,16 @@ class TestTask(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(frappe.db.get_value("Task", task.name, "status"), "Overdue")
|
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(), -10), add_days(nowdate(), 5), save=False)
|
||||||
|
pro = frappe.get_doc("Project", task_end.project)
|
||||||
|
pro.expected_end_date = add_days(nowdate(), 20)
|
||||||
|
pro.save()
|
||||||
|
self.assertRaises(EndDateConnotGreaterThanProjecteEndDateError, task_end.save)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def create_task(subject, start=None, end=None, save=True, depends_on=None, project=None):
|
||||||
if not frappe.db.exists("Task", subject):
|
if not frappe.db.exists("Task", subject):
|
||||||
task = frappe.new_doc('Task')
|
task = frappe.new_doc('Task')
|
||||||
task.status = "Open"
|
task.status = "Open"
|
||||||
@ -105,7 +114,8 @@ def create_task(subject, start=None, end=None, depends_on=None, project=None):
|
|||||||
task.exp_start_date = start or nowdate()
|
task.exp_start_date = start or nowdate()
|
||||||
task.exp_end_date = end or nowdate()
|
task.exp_end_date = end or nowdate()
|
||||||
task.project = project or "_Test Project"
|
task.project = project or "_Test Project"
|
||||||
task.save()
|
if save:
|
||||||
|
task.save()
|
||||||
else:
|
else:
|
||||||
task = frappe.get_doc("Task", subject)
|
task = frappe.get_doc("Task", subject)
|
||||||
|
|
||||||
@ -113,6 +123,7 @@ def create_task(subject, start=None, end=None, depends_on=None, project=None):
|
|||||||
task.append("depends_on", {
|
task.append("depends_on", {
|
||||||
"task": depends_on
|
"task": depends_on
|
||||||
})
|
})
|
||||||
task.save()
|
if save:
|
||||||
|
task.save()
|
||||||
|
|
||||||
return task
|
return task
|
Loading…
x
Reference in New Issue
Block a user