Merge pull request #7038 from rmehta/unassign-rule-fix
Unassignment rule
This commit is contained in:
commit
d7ebaa07e9
4 changed files with 627 additions and 564 deletions
|
|
@ -16,17 +16,25 @@ class AssignmentRule(Document):
|
|||
frappe.cache().delete_value('assignment_rule')
|
||||
|
||||
def apply(self, doc):
|
||||
assignments = assign_to.get(doc)
|
||||
assignments = self.get_assignments(doc)
|
||||
if not assignments and self.safe_eval('assign_condition', doc):
|
||||
self.do_assignment(doc)
|
||||
return True
|
||||
|
||||
# try clearing
|
||||
if assignments and self.unassign_condition:
|
||||
if (self.unassign_condition and assignments and
|
||||
self.name in [d.assignment_rule for d in assignments]):
|
||||
return self.clear_assignment(doc)
|
||||
|
||||
return False
|
||||
|
||||
def get_assignments(self, doc):
|
||||
return frappe.get_all('ToDo', fields = ['name', 'assignment_rule'], filters = dict(
|
||||
reference_type = doc.get('doctype'),
|
||||
reference_name = doc.get('name'),
|
||||
status = 'Open'
|
||||
), limit = 5)
|
||||
|
||||
def do_assignment(self, doc):
|
||||
# clear existing assignment, to reassign
|
||||
assign_to.clear(doc.get('doctype'), doc.get('name'))
|
||||
|
|
@ -37,7 +45,8 @@ class AssignmentRule(Document):
|
|||
assign_to = user,
|
||||
doctype = doc.get('doctype'),
|
||||
name = doc.get('name'),
|
||||
description = frappe.render_template(self.description, doc)
|
||||
description = frappe.render_template(self.description, doc),
|
||||
assignment_rule = self.name
|
||||
))
|
||||
|
||||
# set for reference in round robin
|
||||
|
|
@ -95,10 +104,10 @@ class AssignmentRule(Document):
|
|||
def safe_eval(self, fieldname, doc):
|
||||
try:
|
||||
return frappe.safe_eval(self.get(fieldname), None, doc)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
# when assignment fails, don't block the document as it may be
|
||||
# a part of the email pulling
|
||||
frappe.msgprint(frappe._('Auto assignment failed'), indicator = 'orange')
|
||||
frappe.msgprint(frappe._('Auto assignment failed: {0}').format(str(e)), indicator = 'orange')
|
||||
|
||||
def apply(doc, method):
|
||||
if frappe.flags.in_patch or frappe.flags.in_install:
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ def get_assignment_rule():
|
|||
priority = 0,
|
||||
document_type = 'Note',
|
||||
assign_condition = 'public == 1',
|
||||
unassign_condition = 'pubic == 0 or notify_on_login == 1',
|
||||
unassign_condition = 'public == 0 or notify_on_login == 1',
|
||||
rule = 'Round Robin',
|
||||
users = [
|
||||
dict(user = 'test@example.com'),
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -29,7 +29,8 @@ def add(args=None):
|
|||
"assign_to": ,
|
||||
"doctype": ,
|
||||
"name": ,
|
||||
"description":
|
||||
"description": ,
|
||||
"assignment_rule":
|
||||
}
|
||||
|
||||
"""
|
||||
|
|
@ -62,6 +63,7 @@ def add(args=None):
|
|||
"status": "Open",
|
||||
"date": args.get('date', nowdate()),
|
||||
"assigned_by": args.get('assigned_by', frappe.session.user),
|
||||
'assignment_rule': args.get('assignment_rule')
|
||||
}).insert(ignore_permissions=True)
|
||||
|
||||
# set assigned_to if field exists
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue