From f7cf745fb5eed9338ba3e7d1063d540095564d5c Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 4 Mar 2019 16:15:22 +0530 Subject: [PATCH] fix: assginment rule only reassign if not assigned --- .../doctype/assignment_rule/assignment_rule.json | 6 +++--- .../doctype/assignment_rule/assignment_rule.py | 2 +- .../assignment_rule/test_assignment_rule.py | 2 +- frappe/desk/form/assign_to.py | 14 ++++---------- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/frappe/automation/doctype/assignment_rule/assignment_rule.json b/frappe/automation/doctype/assignment_rule/assignment_rule.json index 014c2ba2c7..f64a965028 100644 --- a/frappe/automation/doctype/assignment_rule/assignment_rule.json +++ b/frappe/automation/doctype/assignment_rule/assignment_rule.json @@ -217,7 +217,7 @@ "bold": 0, "collapsible": 0, "columns": 0, - "description": "Example: status == \"Open\"", + "description": "Simple Python Expression, Example: status == 'Open' and type == 'Bug'", "fieldname": "assign_condition", "fieldtype": "Small Text", "hidden": 0, @@ -281,7 +281,7 @@ "bold": 0, "collapsible": 0, "columns": 0, - "description": "Example: Status in (\"Closed\", \"Cancelled\")", + "description": "Simple Python Expression, Example: Status in (\"Closed\", \"Cancelled\")", "fieldname": "unassign_condition", "fieldtype": "Small Text", "hidden": 0, @@ -449,7 +449,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2019-02-28 17:12:44.413781", + "modified": "2019-02-28 17:12:44.413782", "modified_by": "Administrator", "module": "Automation", "name": "Assignment Rule", diff --git a/frappe/automation/doctype/assignment_rule/assignment_rule.py b/frappe/automation/doctype/assignment_rule/assignment_rule.py index 208efe7b95..a4013a1563 100644 --- a/frappe/automation/doctype/assignment_rule/assignment_rule.py +++ b/frappe/automation/doctype/assignment_rule/assignment_rule.py @@ -16,7 +16,7 @@ class AssignmentRule(Document): frappe.cache().delete_value('assignment_rule') def apply(self, doc): - if self.safe_eval('assign_condition', doc): + if not assign_to.get(doc) and self.safe_eval('assign_condition', doc): self.do_assignment(doc) return True diff --git a/frappe/automation/doctype/assignment_rule/test_assignment_rule.py b/frappe/automation/doctype/assignment_rule/test_assignment_rule.py index 654e372b5c..ed7fab43ab 100644 --- a/frappe/automation/doctype/assignment_rule/test_assignment_rule.py +++ b/frappe/automation/doctype/assignment_rule/test_assignment_rule.py @@ -130,7 +130,7 @@ def get_assignment_rule(): priority = 0, document_type = 'Note', assign_condition = 'public == 1', - unassign_condition = 'public == 0', + unassign_condition = 'pubic == 0 or notify_on_login == 1', rule = 'Round Robin', users = [ dict(user = 'test@example.com'), diff --git a/frappe/desk/form/assign_to.py b/frappe/desk/form/assign_to.py index f02dcba6fe..8463916d8e 100644 --- a/frappe/desk/form/assign_to.py +++ b/frappe/desk/form/assign_to.py @@ -6,7 +6,6 @@ from __future__ import unicode_literals import frappe from frappe import _ -from frappe.desk.form.load import get_docinfo import frappe.share class DuplicateToDoError(frappe.ValidationError): pass @@ -16,15 +15,10 @@ def get(args=None): if not args: args = frappe.local.form_dict - get_docinfo(frappe.get_doc(args.get("doctype"), args.get("name"))) - - return frappe.db.sql("""SELECT `owner`, `description` - FROM `tabToDo` - WHERE reference_type=%(doctype)s - AND reference_name=%(name)s - AND status='Open' - ORDER BY modified DESC - LIMIT 5""", args, as_dict=True) + return frappe.get_all('ToDo', fields = ['owner', 'description'], filters = dict( + reference_type = args.get('doctype'), + reference_name = args.get('name') + ), limit = 5) @frappe.whitelist() def add(args=None):