[fix] Close assignment (ToDo) when Task status is changed to Closed
This commit is contained in:
parent
ce81a61fe7
commit
ec60ebde6f
@ -29,6 +29,10 @@ 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'"))
|
||||
|
@ -146,3 +146,34 @@ class TestTask(unittest.TestCase):
|
||||
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