From 19ff2489f1f4e5fc57da72c57f13cac024cf96a0 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Sat, 21 Sep 2019 17:25:56 +0530 Subject: [PATCH] feat: assignment rule days --- .../assignment_rule/assignment_rule.json | 15 +++++++++- .../assignment_rule/assignment_rule.py | 17 +++++++++++ .../doctype/assignment_rule_day/__init__.py | 0 .../assignment_rule_day.json | 28 +++++++++++++++++++ .../assignment_rule_day.py | 10 +++++++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 frappe/automation/doctype/assignment_rule_day/__init__.py create mode 100644 frappe/automation/doctype/assignment_rule_day/assignment_rule_day.json create mode 100644 frappe/automation/doctype/assignment_rule_day/assignment_rule_day.py diff --git a/frappe/automation/doctype/assignment_rule/assignment_rule.json b/frappe/automation/doctype/assignment_rule/assignment_rule.json index 799efefd04..e401881976 100644 --- a/frappe/automation/doctype/assignment_rule/assignment_rule.json +++ b/frappe/automation/doctype/assignment_rule/assignment_rule.json @@ -18,6 +18,8 @@ "unassign_condition", "section_break_10", "close_condition", + "sb", + "assignment_day", "assign_to_users_section", "rule", "users", @@ -115,9 +117,20 @@ "fieldname": "close_condition", "fieldtype": "Code", "label": "Close Condition" + }, + { + "fieldname": "sb", + "fieldtype": "Section Break", + "label": "Assignment Days" + }, + { + "fieldname": "assignment_day", + "fieldtype": "Table", + "label": "Assignment Days", + "options": "Assignment Rule Day" } ], - "modified": "2019-09-10 14:45:53.657667", + "modified": "2019-09-21 16:54:10.370154", "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 f4c4a25830..0ba64b6595 100644 --- a/frappe/automation/doctype/assignment_rule/assignment_rule.py +++ b/frappe/automation/doctype/assignment_rule/assignment_rule.py @@ -118,6 +118,9 @@ class AssignmentRule(Document): return False + def get_assignment_days(self): + return [d.day for d in self.assignment_days] + def get_assignments(doc): return frappe.get_all('ToDo', fields = ['name', 'assignment_rule'], filters = dict( reference_type = doc.get('doctype'), @@ -175,12 +178,18 @@ def apply(doc, method=None, doctype=None, name=None): clear = True # are all assignments cleared new_apply = False # are new assignments applied + today = frappe.utils.get_weekday() + if assignments: # first unassign # use case, there are separate groups to be assigned for say L1 and L2, # so when the value switches from L1 to L2, L1 team must be unassigned, then L2 can be assigned. clear = False for assignment_rule in assignment_rule_docs: + assignment_rule_days = assignment_rule.get_assignment_days() + if assignment_rule_days and not today in assignment_rule_days: + continue + clear = assignment_rule.apply_unassign(doc, assignments) if clear: break @@ -188,6 +197,10 @@ def apply(doc, method=None, doctype=None, name=None): # apply rule only if there are no existing assignments if clear: for assignment_rule in assignment_rule_docs: + assignment_rule_days = assignment_rule.get_assignment_days() + if assignment_rule_days and not today in assignment_rule_days: + continue + new_apply = assignment_rule.apply_assign(doc) if new_apply: break @@ -196,6 +209,10 @@ def apply(doc, method=None, doctype=None, name=None): assignments = get_assignments(doc) if assignments: for assignment_rule in assignment_rule_docs: + assignment_rule_days = assignment_rule.get_assignment_days() + if assignment_rule_days and not today in assignment_rule_days: + continue + if not new_apply: reopen = reopen_closed_assignment(doc) if reopen: diff --git a/frappe/automation/doctype/assignment_rule_day/__init__.py b/frappe/automation/doctype/assignment_rule_day/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frappe/automation/doctype/assignment_rule_day/assignment_rule_day.json b/frappe/automation/doctype/assignment_rule_day/assignment_rule_day.json new file mode 100644 index 0000000000..2a4187965c --- /dev/null +++ b/frappe/automation/doctype/assignment_rule_day/assignment_rule_day.json @@ -0,0 +1,28 @@ +{ + "creation": "2019-09-21 16:52:01.705351", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "day" + ], + "fields": [ + { + "fieldname": "day", + "fieldtype": "Select", + "in_list_view": 1, + "label": "Day", + "options": "Monday\nTuesday\nWednesday\nThursday\nFriday\nSaturday\nSunday" + } + ], + "istable": 1, + "modified": "2019-09-21 16:55:09.376291", + "modified_by": "Administrator", + "module": "Automation", + "name": "Assignment Rule Day", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/frappe/automation/doctype/assignment_rule_day/assignment_rule_day.py b/frappe/automation/doctype/assignment_rule_day/assignment_rule_day.py new file mode 100644 index 0000000000..27f9aa40e1 --- /dev/null +++ b/frappe/automation/doctype/assignment_rule_day/assignment_rule_day.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2019, Frappe Technologies and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +# import frappe +from frappe.model.document import Document + +class AssignmentRuleDay(Document): + pass