Compare commits
1 Commits
develop
...
feat-autom
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50dbe3628d |
0
helpdesk/helpdesk/doctype/hd_automation/__init__.py
Normal file
0
helpdesk/helpdesk/doctype/hd_automation/__init__.py
Normal file
8
helpdesk/helpdesk/doctype/hd_automation/hd_automation.js
Normal file
8
helpdesk/helpdesk/doctype/hd_automation/hd_automation.js
Normal file
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2024, Frappe Technologies and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
// frappe.ui.form.on("HD Automation", {
|
||||
// refresh(frm) {
|
||||
|
||||
// },
|
||||
// });
|
||||
66
helpdesk/helpdesk/doctype/hd_automation/hd_automation.json
Normal file
66
helpdesk/helpdesk/doctype/hd_automation/hd_automation.json
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"actions": [],
|
||||
"autoname": "autoincrement",
|
||||
"creation": "2024-11-08 15:42:05.926888",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"enabled",
|
||||
"title",
|
||||
"event",
|
||||
"rule"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "event",
|
||||
"fieldtype": "Select",
|
||||
"label": "Event",
|
||||
"options": "On ticket creation\nOn ticket update",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "rule",
|
||||
"fieldtype": "JSON",
|
||||
"label": "Rule",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "enabled",
|
||||
"fieldtype": "Check",
|
||||
"label": "Enabled"
|
||||
},
|
||||
{
|
||||
"fieldname": "title",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Title",
|
||||
"reqd": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2024-11-08 16:05:05.024957",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Helpdesk",
|
||||
"name": "HD Automation",
|
||||
"naming_rule": "Autoincrement",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
||||
38
helpdesk/helpdesk/doctype/hd_automation/hd_automation.py
Normal file
38
helpdesk/helpdesk/doctype/hd_automation/hd_automation.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# Copyright (c) 2024, Frappe Technologies and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
ADD_TO_GROUP_ACTION = {
|
||||
"fields": [
|
||||
{"fieldtype": "select", "label": "Group", "fieldname": "group"},
|
||||
{"fieldtype": "select", "label": "Type", "fieldname": "type"},
|
||||
]
|
||||
}
|
||||
|
||||
# [
|
||||
# {
|
||||
# "action": "Add to group",
|
||||
# "payload": {
|
||||
# "group": "Business",
|
||||
# "type": "Round Robin"
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
|
||||
|
||||
|
||||
class HDAutomation(Document):
|
||||
def apply(self, doc, event):
|
||||
if doc.doctype == "HD Ticket":
|
||||
pass
|
||||
|
||||
|
||||
def apply_automations(doc, event):
|
||||
automations = frappe.db.get_all(
|
||||
"HD Automation",
|
||||
{"enabled": 1, "event": ("in", ["On ticket creation", "On ticket update"])},
|
||||
)
|
||||
for automation in automations:
|
||||
automation.apply(doc, event)
|
||||
@@ -0,0 +1,57 @@
|
||||
# Copyright (c) 2024, Frappe Technologies and Contributors
|
||||
# See license.txt
|
||||
|
||||
import frappe
|
||||
import json
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
|
||||
# On IntegrationTestCase, the doctype test records and all
|
||||
# link-field test record depdendencies are recursively loaded
|
||||
# Use these module variables to add/remove to/from that list
|
||||
EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]
|
||||
IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]
|
||||
|
||||
|
||||
class TestHDAutomation(UnitTestCase):
|
||||
"""
|
||||
Unit tests for HDAutomation.
|
||||
Use this class for testing individual functions and methods.
|
||||
"""
|
||||
|
||||
def test_assign_group(self):
|
||||
user1 = frappe.new_doc(
|
||||
"User", first_name="Agent 1", email="agent1@example.com"
|
||||
).insert()
|
||||
agent1 = frappe.new_doc("HD Agent", user=user1.name)
|
||||
billing_team = frappe.new_doc(
|
||||
"HD Team", team_name="Billing", users=[{"user": user1.name}]
|
||||
)
|
||||
|
||||
automation = frappe.new_doc(
|
||||
"HD Automation",
|
||||
enabled=1,
|
||||
title="Set group automatically",
|
||||
event="On ticket creation",
|
||||
rule=json.dumps(
|
||||
{
|
||||
"condition": "and",
|
||||
"rules": [
|
||||
{"field": "subject", "operator": "like", "value": "%billing%"},
|
||||
],
|
||||
}
|
||||
),
|
||||
).insert()
|
||||
|
||||
ticket = frappe.new_doc("HD Ticket", subject="my billing is not working").insert()
|
||||
|
||||
self.assertEqual(ticket.agent_group, "Billing")
|
||||
|
||||
|
||||
class TestHDAutomation(IntegrationTestCase):
|
||||
"""
|
||||
Integration tests for HDAutomation.
|
||||
Use this class for testing interactions between multiple components.
|
||||
"""
|
||||
|
||||
pass
|
||||
@@ -38,6 +38,10 @@ website_route_rules = [
|
||||
]
|
||||
|
||||
doc_events = {
|
||||
"HD Ticket": {
|
||||
"before_insert": "helpdesk.helpdesk.doctype.hd_automation.hd_automation.apply_automations",
|
||||
"on_update": "helpdesk.helpdesk.doctype.hd_automation.hd_automation.apply_automations"
|
||||
},
|
||||
"Contact": {
|
||||
"before_insert": "helpdesk.helpdesk.hooks.contact.before_insert",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user