Test Cases Added, fixes in task
This commit is contained in:
parent
3da42fcdf9
commit
1fa8ed8a1f
@ -9,6 +9,8 @@ from frappe import _
|
||||
|
||||
from frappe.model.document import Document
|
||||
|
||||
class ReferenceError(frappe.ValidationError): pass
|
||||
|
||||
class Task(Document):
|
||||
def get_feed(self):
|
||||
return '{0}: {1}'.format(_(self.status), self.subject)
|
||||
@ -53,8 +55,8 @@ class Task(Document):
|
||||
def update_time_and_costing(self):
|
||||
tl = frappe.db.sql("""select min(from_time) as start_date, max(to_time) as end_date,
|
||||
sum(billing_amount) as total_billing_amount, sum(costing_amount) as total_costing_amount,
|
||||
sum(hours) as time from `tabTime Log` where project = %s and task = %s and docstatus=1""",
|
||||
(self.project, self.name),as_dict=1)[0]
|
||||
sum(hours) as time from `tabTime Log` where task = %s and docstatus=1"""
|
||||
,self.name, as_dict=1)[0]
|
||||
if self.status == "Open":
|
||||
self.status = "Working"
|
||||
self.total_costing_amount= tl.total_costing_amount
|
||||
@ -80,7 +82,7 @@ class Task(Document):
|
||||
|
||||
def check_recursion(self, task, task_list):
|
||||
if task in task_list:
|
||||
frappe.throw("Circular Reference Error")
|
||||
frappe.throw("Circular Reference Error", ReferenceError)
|
||||
else :
|
||||
task_list.append(task)
|
||||
return frappe.db.get_value("Task", task, "depends_on")
|
||||
|
@ -1,7 +1,95 @@
|
||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
import frappe
|
||||
import unittest
|
||||
from frappe.utils import getdate
|
||||
|
||||
test_records = frappe.get_test_records('Task')
|
||||
|
||||
from erpnext.projects.doctype.task.task import ReferenceError
|
||||
|
||||
class TestTask(unittest.TestCase):
|
||||
def test_circular_refereence(self):
|
||||
task1 = frappe.new_doc('Task')
|
||||
task1.update({
|
||||
"status": "Open",
|
||||
"subject": "_Test Task 3"
|
||||
})
|
||||
task1.save()
|
||||
|
||||
task2 = frappe.new_doc('Task')
|
||||
task2.update({
|
||||
"status": "Open",
|
||||
"subject": "_Test Task 4",
|
||||
"depends_on": task1.name
|
||||
})
|
||||
task2.save()
|
||||
|
||||
task3 = frappe.new_doc('Task')
|
||||
task3.update({
|
||||
"status": "Open",
|
||||
"subject": "_Test Task 5",
|
||||
"depends_on": task2.name
|
||||
})
|
||||
task3.save()
|
||||
|
||||
task1.update({
|
||||
"depends_on": task3.name
|
||||
})
|
||||
self.assertRaises(ReferenceError, task1.save)
|
||||
|
||||
def test_reschedule_depending_task(self):
|
||||
task1 = frappe.new_doc('Task')
|
||||
task1.update({
|
||||
"status": "Open",
|
||||
"subject": "_Test Task 6",
|
||||
"exp_start_date": "2015-1-1",
|
||||
"exp_end_date": "2015-1-10"
|
||||
})
|
||||
task1.save()
|
||||
|
||||
task2 = frappe.new_doc('Task')
|
||||
task2.update({
|
||||
"status": "Open",
|
||||
"subject": "_Test Task 7",
|
||||
"exp_start_date": "2015-1-11",
|
||||
"exp_end_date": "2015-1-15",
|
||||
"depends_on": task1.name
|
||||
})
|
||||
task2.save()
|
||||
|
||||
task3 = frappe.new_doc('Task')
|
||||
task3.update({
|
||||
"status": "Open",
|
||||
"subject": "_Test Task 5",
|
||||
"exp_start_date": "2015-1-16",
|
||||
"exp_end_date": "2015-1-18",
|
||||
"depends_on": task2.name
|
||||
})
|
||||
task3.save()
|
||||
|
||||
task1.update({
|
||||
"exp_end_date": "2015-1-20"
|
||||
})
|
||||
task1.save()
|
||||
|
||||
self.assertEqual(frappe.db.get_value("Task", task2.name, "exp_start_date"), getdate('2015-1-21'))
|
||||
self.assertEqual(frappe.db.get_value("Task", task2.name, "exp_end_date"), getdate('2015-1-25'))
|
||||
|
||||
self.assertEqual(frappe.db.get_value("Task", task3.name, "exp_start_date"), getdate('2015-1-26'))
|
||||
self.assertEqual(frappe.db.get_value("Task", task3.name, "exp_end_date"), getdate('2015-1-28'))
|
||||
|
||||
time_log = frappe.new_doc('Time Log')
|
||||
time_log.update({
|
||||
"from_time": "2015-1-1",
|
||||
"to_time": "2015-1-22",
|
||||
"task": task1.name
|
||||
})
|
||||
time_log.submit()
|
||||
|
||||
self.assertEqual(frappe.db.get_value("Task", task2.name, "exp_start_date"), getdate('2015-1-23'))
|
||||
self.assertEqual(frappe.db.get_value("Task", task2.name, "exp_end_date"), getdate('2015-1-27'))
|
||||
|
||||
self.assertEqual(frappe.db.get_value("Task", task3.name, "exp_start_date"), getdate('2015-1-28'))
|
||||
self.assertEqual(frappe.db.get_value("Task", task3.name, "exp_end_date"), getdate('2015-1-30'))
|
@ -1,6 +1,5 @@
|
||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
Loading…
Reference in New Issue
Block a user