Merge pull request #3437 from anandpdoshi/task-close-assignment
[fix] Close assignment (ToDo) when Task status is changed to Closed
This commit is contained in:
commit
41413af42d
@ -28,7 +28,11 @@ class Task(Document):
|
||||
|
||||
def validate(self):
|
||||
self.validate_dates()
|
||||
|
||||
|
||||
if self.status!=self.get_db_value("status") and self.status == "Closed":
|
||||
from frappe.desk.form.assign_to import clear
|
||||
clear(self.doctype, self.name)
|
||||
|
||||
def validate_dates(self):
|
||||
if self.exp_start_date and self.exp_end_date and getdate(self.exp_start_date) > getdate(self.exp_end_date):
|
||||
frappe.throw(_("'Expected Start Date' can not be greater than 'Expected End Date'"))
|
||||
@ -41,17 +45,17 @@ class Task(Document):
|
||||
self.reschedule_dependent_tasks()
|
||||
self.update_percentage()
|
||||
self.update_project()
|
||||
|
||||
|
||||
def update_percentage(self):
|
||||
"""update percent complete in project"""
|
||||
if self.project and not self.flags.from_project:
|
||||
project = frappe.get_doc("Project", self.project)
|
||||
project.run_method("update_percent_complete")
|
||||
|
||||
|
||||
def update_total_expense_claim(self):
|
||||
self.total_expense_claim = frappe.db.sql("""select sum(total_sanctioned_amount) from `tabExpense Claim`
|
||||
self.total_expense_claim = frappe.db.sql("""select sum(total_sanctioned_amount) from `tabExpense Claim`
|
||||
where project = %s and task = %s and approval_status = "Approved" and docstatus=1""",(self.project, self.name))
|
||||
|
||||
|
||||
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,
|
||||
@ -64,14 +68,14 @@ class Task(Document):
|
||||
self.actual_time= tl.time
|
||||
self.act_start_date= tl.start_date
|
||||
self.act_end_date= tl.end_date
|
||||
|
||||
|
||||
def update_project(self):
|
||||
if self.project and frappe.db.exists("Project", self.project):
|
||||
project = frappe.get_doc("Project", self.project)
|
||||
project.flags.dont_sync_tasks = True
|
||||
project.update_costing()
|
||||
project.save()
|
||||
|
||||
|
||||
def check_recursion(self):
|
||||
if self.flags.ignore_recursion_check: return
|
||||
check_list = [['task', 'parent'], ['parent', 'task']]
|
||||
@ -88,7 +92,7 @@ class Task(Document):
|
||||
task_list.append(b[0])
|
||||
if count == 15:
|
||||
break
|
||||
|
||||
|
||||
def reschedule_dependent_tasks(self):
|
||||
end_date = self.exp_end_date or self.act_end_date
|
||||
if end_date:
|
||||
|
@ -11,19 +11,19 @@ from erpnext.projects.doctype.task.task import CircularReferenceError
|
||||
|
||||
class TestTask(unittest.TestCase):
|
||||
def test_circular_reference(self):
|
||||
|
||||
|
||||
task1 = frappe.new_doc('Task')
|
||||
task1.update({
|
||||
"status": "Open",
|
||||
"status": "Open",
|
||||
"subject": "_Test Task 1",
|
||||
"exp_start_date": "2015-1-1",
|
||||
"exp_end_date": "2015-1-10"
|
||||
})
|
||||
task1.save()
|
||||
|
||||
|
||||
task2 = frappe.new_doc('Task')
|
||||
task2.update({
|
||||
"status": "Open",
|
||||
"status": "Open",
|
||||
"subject": "_Test Task 2",
|
||||
"exp_start_date": "2015-1-11",
|
||||
"exp_end_date": "2015-1-15",
|
||||
@ -34,10 +34,10 @@ class TestTask(unittest.TestCase):
|
||||
]
|
||||
})
|
||||
task2.save()
|
||||
|
||||
|
||||
task3 = frappe.new_doc('Task')
|
||||
task3.update({
|
||||
"status": "Open",
|
||||
"status": "Open",
|
||||
"subject": "_Test Task 2",
|
||||
"exp_start_date": "2015-1-11",
|
||||
"exp_end_date": "2015-1-15",
|
||||
@ -53,13 +53,13 @@ class TestTask(unittest.TestCase):
|
||||
"task": task3.name
|
||||
})
|
||||
self.assertRaises(CircularReferenceError, task1.save)
|
||||
|
||||
|
||||
task1.set("depends_on", [])
|
||||
task1.save()
|
||||
|
||||
|
||||
task4 = frappe.new_doc('Task')
|
||||
task4.update({
|
||||
"status": "Open",
|
||||
"status": "Open",
|
||||
"subject": "_Test Task 1",
|
||||
"exp_start_date": "2015-1-1",
|
||||
"exp_end_date": "2015-1-15",
|
||||
@ -74,20 +74,20 @@ class TestTask(unittest.TestCase):
|
||||
task3.append("depends_on", {
|
||||
"task": task4.name
|
||||
})
|
||||
|
||||
|
||||
def test_reschedule_dependent_task(self):
|
||||
task1 = frappe.new_doc('Task')
|
||||
task1.update({
|
||||
"status": "Open",
|
||||
"status": "Open",
|
||||
"subject": "_Test Task 1",
|
||||
"exp_start_date": "2015-1-1",
|
||||
"exp_end_date": "2015-1-10"
|
||||
})
|
||||
task1.save()
|
||||
|
||||
|
||||
task2 = frappe.new_doc('Task')
|
||||
task2.update({
|
||||
"status": "Open",
|
||||
"status": "Open",
|
||||
"subject": "_Test Task 2",
|
||||
"exp_start_date": "2015-1-11",
|
||||
"exp_end_date": "2015-1-15",
|
||||
@ -98,10 +98,10 @@ class TestTask(unittest.TestCase):
|
||||
]
|
||||
})
|
||||
task2.save()
|
||||
|
||||
|
||||
task3 = frappe.new_doc('Task')
|
||||
task3.update({
|
||||
"status": "Open",
|
||||
"status": "Open",
|
||||
"subject": "_Test Task 3",
|
||||
"exp_start_date": "2015-1-16",
|
||||
"exp_end_date": "2015-1-18",
|
||||
@ -112,18 +112,18 @@ class TestTask(unittest.TestCase):
|
||||
]
|
||||
})
|
||||
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",
|
||||
@ -131,18 +131,49 @@ class TestTask(unittest.TestCase):
|
||||
"task": task1.name
|
||||
})
|
||||
time_log.submit()
|
||||
|
||||
|
||||
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.cancel()
|
||||
|
||||
|
||||
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'))
|
||||
|
||||
|
||||
|
||||
def test_close_assignment(self):
|
||||
task = frappe.new_doc("Task")
|
||||
task.subject = "Test Close Assignment"
|
||||
task.insert()
|
||||
|
||||
def assign():
|
||||
from frappe.desk.form import assign_to
|
||||
assign_to.add({
|
||||
"assign_to": "test@example.com",
|
||||
"doctype": task.doctype,
|
||||
"name": task.name,
|
||||
"description": "Close this task"
|
||||
})
|
||||
|
||||
def get_owner_and_status():
|
||||
return frappe.db.get_value("ToDo", filters={"reference_type": task.doctype, "reference_name": task.name,
|
||||
"description": "Close this task"}, fieldname=("owner", "status"), as_dict=True)
|
||||
|
||||
assign()
|
||||
todo = get_owner_and_status()
|
||||
self.assertEquals(todo.owner, "test@example.com")
|
||||
self.assertEquals(todo.status, "Open")
|
||||
|
||||
# assignment should be
|
||||
task.load_from_db()
|
||||
task.status = "Closed"
|
||||
task.save()
|
||||
todo = get_owner_and_status()
|
||||
self.assertEquals(todo.owner, "test@example.com")
|
||||
self.assertEquals(todo.status, "Closed")
|
||||
|
Loading…
x
Reference in New Issue
Block a user