@cubocicloide/stack-frappe 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +33 -0
- package/README.md +37 -0
- package/dist/commands/lint/checks/APP/001.d.ts +13 -0
- package/dist/commands/lint/checks/APP/001.js +73 -0
- package/dist/commands/lint/checks/APP/001.js.map +1 -0
- package/dist/commands/lint/checks/APP/002.d.ts +12 -0
- package/dist/commands/lint/checks/APP/002.js +94 -0
- package/dist/commands/lint/checks/APP/002.js.map +1 -0
- package/dist/commands/lint/checks/APP/003.d.ts +12 -0
- package/dist/commands/lint/checks/APP/003.js +94 -0
- package/dist/commands/lint/checks/APP/003.js.map +1 -0
- package/dist/commands/lint/checks/APP/004.d.ts +12 -0
- package/dist/commands/lint/checks/APP/004.js +117 -0
- package/dist/commands/lint/checks/APP/004.js.map +1 -0
- package/dist/commands/lint/checks/DT/001.d.ts +11 -0
- package/dist/commands/lint/checks/DT/001.js +57 -0
- package/dist/commands/lint/checks/DT/001.js.map +1 -0
- package/dist/commands/lint/checks/DT/002.d.ts +12 -0
- package/dist/commands/lint/checks/DT/002.js +74 -0
- package/dist/commands/lint/checks/DT/002.js.map +1 -0
- package/dist/commands/lint/checks/DT/003.d.ts +13 -0
- package/dist/commands/lint/checks/DT/003.js +96 -0
- package/dist/commands/lint/checks/DT/003.js.map +1 -0
- package/dist/commands/lint/checks/DT/004.d.ts +12 -0
- package/dist/commands/lint/checks/DT/004.js +101 -0
- package/dist/commands/lint/checks/DT/004.js.map +1 -0
- package/dist/commands/lint/checks/PY/001.d.ts +12 -0
- package/dist/commands/lint/checks/PY/001.js +87 -0
- package/dist/commands/lint/checks/PY/001.js.map +1 -0
- package/dist/commands/lint/checks/PY/002.d.ts +12 -0
- package/dist/commands/lint/checks/PY/002.js +80 -0
- package/dist/commands/lint/checks/PY/002.js.map +1 -0
- package/dist/commands/lint/checks/PY/003.d.ts +11 -0
- package/dist/commands/lint/checks/PY/003.js +56 -0
- package/dist/commands/lint/checks/PY/003.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1987 -0
- package/dist/index.js.map +1 -0
- package/dude.stack.json +12 -0
- package/package.json +41 -0
- package/templates/aws-ecs/_dockerignore +11 -0
- package/templates/aws-ecs/docker/Dockerfile.prod.hbs +80 -0
- package/templates/aws-ecs/docker/nginx-entrypoint.sh +17 -0
- package/templates/aws-ecs/docker/nginx-template.conf +95 -0
- package/templates/aws-ecs/docs/docs/deploy.md.hbs +53 -0
- package/templates/aws-ecs/iac/README.md.hbs +113 -0
- package/templates/aws-ecs/iac/_gitignore +14 -0
- package/templates/aws-ecs/iac/runner/Dockerfile +35 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/main.tf.hbs +93 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/outputs.tf +14 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/variables.tf.hbs +17 -0
- package/templates/aws-ecs/iac/terraform/environments/dev/backend.hcl.hbs +12 -0
- package/templates/aws-ecs/iac/terraform/environments/dev/terraform.tfvars.hbs +32 -0
- package/templates/aws-ecs/iac/terraform/main.tf.hbs +1205 -0
- package/templates/aws-ecs/iac/terraform/outputs.tf.hbs +103 -0
- package/templates/aws-ecs/iac/terraform/providers.tf +19 -0
- package/templates/aws-ecs/iac/terraform/variables.tf.hbs +139 -0
- package/templates/aws-ecs/iac/terraform/versions.tf +19 -0
- package/templates/base/.claude/rules/APP/001.md +26 -0
- package/templates/base/.claude/rules/APP/002.md +26 -0
- package/templates/base/.claude/rules/APP/003.md +25 -0
- package/templates/base/.claude/rules/APP/004.md +27 -0
- package/templates/base/.claude/rules/DT/001.md +25 -0
- package/templates/base/.claude/rules/DT/002.md +25 -0
- package/templates/base/.claude/rules/DT/003.md +24 -0
- package/templates/base/.claude/rules/DT/004.md +22 -0
- package/templates/base/.claude/rules/PY/001.md +30 -0
- package/templates/base/.claude/rules/PY/002.md +31 -0
- package/templates/base/.claude/rules/PY/003.md +29 -0
- package/templates/base/.claude/settings.json +42 -0
- package/templates/base/.claude/skills/create-doctype/SKILL.md +99 -0
- package/templates/base/.dude/commands/README.md +85 -0
- package/templates/base/.dude/commands/hello.ts +34 -0
- package/templates/base/.dude/lint/checks/PRJ/001.ts +26 -0
- package/templates/base/.dude/lint/checks/README.md +69 -0
- package/templates/base/.vscode/tasks.json +44 -0
- package/templates/base/CLAUDE.md.hbs +49 -0
- package/templates/base/README.md.hbs +68 -0
- package/templates/base/_env.example.hbs +5 -0
- package/templates/base/_env.hbs +12 -0
- package/templates/base/_gitignore +26 -0
- package/templates/base/_npmrc +2 -0
- package/templates/base/apps/README.md +24 -0
- package/templates/base/apps/ticketing/README.md +43 -0
- package/templates/base/apps/ticketing/pyproject.toml +34 -0
- package/templates/base/apps/ticketing/ticketing/__init__.py +1 -0
- package/templates/base/apps/ticketing/ticketing/api.py +35 -0
- package/templates/base/apps/ticketing/ticketing/events/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/events/hd_ticket.py +32 -0
- package/templates/base/apps/ticketing/ticketing/fixtures/workflow.json +55 -0
- package/templates/base/apps/ticketing/ticketing/fixtures/workflow_action_master.json +12 -0
- package/templates/base/apps/ticketing/ticketing/fixtures/workflow_state.json +20 -0
- package/templates/base/apps/ticketing/ticketing/hooks.py +54 -0
- package/templates/base/apps/ticketing/ticketing/modules.txt +1 -0
- package/templates/base/apps/ticketing/ticketing/patches/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/patches/v1_0/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/patches/v1_0/set_default_branding.py +26 -0
- package/templates/base/apps/ticketing/ticketing/patches.txt +5 -0
- package/templates/base/apps/ticketing/ticketing/public/images/favicon.png +0 -0
- package/templates/base/apps/ticketing/ticketing/public/images/logo.png +0 -0
- package/templates/base/apps/ticketing/ticketing/tasks.py +99 -0
- package/templates/base/apps/ticketing/ticketing/templates/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/templates/pages/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/templates/pages/ticket_stats.html +30 -0
- package/templates/base/apps/ticketing/ticketing/templates/pages/ticket_stats.py +14 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/test_ticket_escalation_rule.py +32 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.js +23 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.json +99 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.py +18 -0
- package/templates/base/docker/init.sh +114 -0
- package/templates/base/docker-compose.yml.hbs +62 -0
- package/templates/base/docs/docs/api.md +21 -0
- package/templates/base/docs/docs/dude.md.hbs +220 -0
- package/templates/base/docs/docs/extending.md +238 -0
- package/templates/base/docs/docs/frappe.md.hbs +223 -0
- package/templates/base/docs/docs/index.md.hbs +101 -0
- package/templates/base/docs/docs/mkdocs.md +235 -0
- package/templates/base/docs/mkdocs.yml.hbs +54 -0
- package/templates/base/package.json.hbs +11 -0
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""doc_events handlers for Helpdesk's HD Ticket (see hooks.py).
|
|
2
|
+
|
|
3
|
+
Each handler is a plain function taking (doc, method). `doc` is the HD Ticket
|
|
4
|
+
document being saved; `method` is the event name. This is the canonical way
|
|
5
|
+
to extend a DocType owned by another app without forking it.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import frappe
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def after_insert(doc, method=None) -> None:
|
|
12
|
+
"""Welcome-stamp new tickets so agents see the intake time at a glance."""
|
|
13
|
+
doc.add_comment(
|
|
14
|
+
"Comment",
|
|
15
|
+
"Ticket received — the ticketing app is watching this ticket "
|
|
16
|
+
"(auto-escalation is active for approved rules).",
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def on_update(doc, method=None) -> None:
|
|
21
|
+
"""Log status transitions to the Frappe log for observability.
|
|
22
|
+
|
|
23
|
+
`doc.get_doc_before_save()` returns the previous version of the document
|
|
24
|
+
within the same save cycle — the standard way to detect field changes.
|
|
25
|
+
"""
|
|
26
|
+
before = doc.get_doc_before_save()
|
|
27
|
+
if before is None or before.status == doc.status:
|
|
28
|
+
return
|
|
29
|
+
|
|
30
|
+
frappe.logger("ticketing").info(
|
|
31
|
+
f"HD Ticket {doc.name}: status {before.status} -> {doc.status}"
|
|
32
|
+
)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"doctype": "Workflow",
|
|
4
|
+
"name": "Ticket Escalation Rule Approval",
|
|
5
|
+
"workflow_name": "Ticket Escalation Rule Approval",
|
|
6
|
+
"document_type": "Ticket Escalation Rule",
|
|
7
|
+
"workflow_state_field": "workflow_state",
|
|
8
|
+
"is_active": 1,
|
|
9
|
+
"override_status": 0,
|
|
10
|
+
"send_email_alert": 0,
|
|
11
|
+
"states": [
|
|
12
|
+
{
|
|
13
|
+
"state": "Draft",
|
|
14
|
+
"doc_status": "0",
|
|
15
|
+
"allow_edit": "System Manager",
|
|
16
|
+
"is_optional_state": 0
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"state": "Approved",
|
|
20
|
+
"doc_status": "0",
|
|
21
|
+
"allow_edit": "System Manager",
|
|
22
|
+
"is_optional_state": 0
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"state": "Rejected",
|
|
26
|
+
"doc_status": "0",
|
|
27
|
+
"allow_edit": "System Manager",
|
|
28
|
+
"is_optional_state": 0
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"transitions": [
|
|
32
|
+
{
|
|
33
|
+
"state": "Draft",
|
|
34
|
+
"action": "Approve",
|
|
35
|
+
"next_state": "Approved",
|
|
36
|
+
"allowed": "System Manager",
|
|
37
|
+
"allow_self_approval": 1
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"state": "Draft",
|
|
41
|
+
"action": "Reject",
|
|
42
|
+
"next_state": "Rejected",
|
|
43
|
+
"allowed": "System Manager",
|
|
44
|
+
"allow_self_approval": 1
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"state": "Rejected",
|
|
48
|
+
"action": "Approve",
|
|
49
|
+
"next_state": "Approved",
|
|
50
|
+
"allowed": "System Manager",
|
|
51
|
+
"allow_self_approval": 1
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"doctype": "Workflow State",
|
|
4
|
+
"name": "Draft",
|
|
5
|
+
"workflow_state_name": "Draft",
|
|
6
|
+
"style": ""
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"doctype": "Workflow State",
|
|
10
|
+
"name": "Approved",
|
|
11
|
+
"workflow_state_name": "Approved",
|
|
12
|
+
"style": "Success"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"doctype": "Workflow State",
|
|
16
|
+
"name": "Rejected",
|
|
17
|
+
"workflow_state_name": "Rejected",
|
|
18
|
+
"style": "Danger"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""App hooks — the contract between this app and the Frappe framework.
|
|
2
|
+
|
|
3
|
+
Everything the framework needs to know about the app is declared here:
|
|
4
|
+
which events to call us on, which background jobs to schedule, which
|
|
5
|
+
records (fixtures) to ship. Keep this file declarative — put the actual
|
|
6
|
+
logic in dedicated modules (events/, tasks.py, api.py).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
app_name = "ticketing"
|
|
10
|
+
app_title = "Ticketing"
|
|
11
|
+
app_publisher = "Your Team"
|
|
12
|
+
app_description = "Custom ticketing extensions for Frappe Helpdesk — example app"
|
|
13
|
+
app_email = "dev@example.com"
|
|
14
|
+
app_license = "mit"
|
|
15
|
+
|
|
16
|
+
# Branding — Desk navbar logo + default favicon (Website Settings overrides
|
|
17
|
+
# this if set). Swap ticketing/public/images/logo.png and favicon.png with
|
|
18
|
+
# your own files (same names) to rebrand; no code change needed. Helpdesk's
|
|
19
|
+
# own logo/favicon (HD Settings) default to the same files via the
|
|
20
|
+
# set_default_branding patch below.
|
|
21
|
+
app_logo_url = "/assets/ticketing/images/logo.png"
|
|
22
|
+
website_context = {
|
|
23
|
+
"favicon": "/assets/ticketing/images/favicon.png",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# Document events — run code when documents of *any* app change. This is how
|
|
27
|
+
# you extend Frappe Helpdesk without forking it: HD Ticket belongs to the
|
|
28
|
+
# helpdesk app, the handlers live here. Handlers are dotted paths to plain
|
|
29
|
+
# functions taking (doc, method).
|
|
30
|
+
doc_events = {
|
|
31
|
+
"HD Ticket": {
|
|
32
|
+
"after_insert": "ticketing.events.hd_ticket.after_insert",
|
|
33
|
+
"on_update": "ticketing.events.hd_ticket.on_update",
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Scheduler events — background jobs executed by the `schedule` process.
|
|
38
|
+
# Frequencies: all | hourly | daily | weekly | monthly | cron.
|
|
39
|
+
scheduler_events = {
|
|
40
|
+
"hourly": [
|
|
41
|
+
"ticketing.tasks.escalate_overdue_tickets",
|
|
42
|
+
],
|
|
43
|
+
"daily": [
|
|
44
|
+
"ticketing.tasks.close_stale_resolved_tickets",
|
|
45
|
+
],
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# Fixtures — records exported to ticketing/fixtures/*.json and re-imported on
|
|
49
|
+
# every `bench migrate`. Order matters: linked masters first.
|
|
50
|
+
fixtures = [
|
|
51
|
+
{"dt": "Workflow State", "filters": [["name", "in", ["Draft", "Approved", "Rejected"]]]},
|
|
52
|
+
{"dt": "Workflow Action Master", "filters": [["name", "in", ["Approve", "Reject"]]]},
|
|
53
|
+
{"dt": "Workflow", "filters": [["name", "in", ["Ticket Escalation Rule Approval"]]]},
|
|
54
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Ticketing
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""One-time patch: point default branding at ticketing's placeholder assets.
|
|
2
|
+
|
|
3
|
+
Runs once per site (bench migrate). Only fills fields that are still empty,
|
|
4
|
+
so it never clobbers branding an admin already set through the Desk UI.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import frappe
|
|
8
|
+
|
|
9
|
+
LOGO = "/assets/ticketing/images/logo.png"
|
|
10
|
+
FAVICON = "/assets/ticketing/images/favicon.png"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def execute() -> None:
|
|
14
|
+
if not frappe.db.exists("DocType", "HD Settings"):
|
|
15
|
+
return # Helpdesk not installed on this site
|
|
16
|
+
|
|
17
|
+
settings = frappe.get_single("HD Settings")
|
|
18
|
+
changed = False
|
|
19
|
+
if not settings.brand_logo:
|
|
20
|
+
settings.brand_logo = LOGO
|
|
21
|
+
changed = True
|
|
22
|
+
if not settings.favicon:
|
|
23
|
+
settings.favicon = FAVICON
|
|
24
|
+
changed = True
|
|
25
|
+
if changed:
|
|
26
|
+
settings.save(ignore_permissions=True)
|
|
Binary file
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""Background jobs, wired to the scheduler in hooks.py (scheduler_events).
|
|
2
|
+
|
|
3
|
+
Jobs run in the `schedule` process started by `bench start` (dev) or the
|
|
4
|
+
dedicated scheduler service (production). Keep them idempotent: the
|
|
5
|
+
scheduler guarantees at-least-once, not exactly-once, execution.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import frappe
|
|
9
|
+
from frappe.utils import add_to_date, now_datetime
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def escalate_overdue_tickets() -> None:
|
|
13
|
+
"""Hourly: apply enabled, approved Ticket Escalation Rules to open tickets.
|
|
14
|
+
|
|
15
|
+
For every ticket older than a rule's threshold, post a comment and
|
|
16
|
+
assign the rule's escalation contact — a deliberately simple example of
|
|
17
|
+
cross-app orchestration driven by a custom DocType.
|
|
18
|
+
"""
|
|
19
|
+
if not frappe.db.table_exists("HD Ticket"):
|
|
20
|
+
return
|
|
21
|
+
|
|
22
|
+
rules = frappe.get_all(
|
|
23
|
+
"Ticket Escalation Rule",
|
|
24
|
+
filters={"is_enabled": 1, "workflow_state": "Approved"},
|
|
25
|
+
fields=["name", "priority", "hours_until_escalation", "escalate_to"],
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
for rule in rules:
|
|
29
|
+
cutoff = add_to_date(now_datetime(), hours=-rule.hours_until_escalation)
|
|
30
|
+
overdue = frappe.get_all(
|
|
31
|
+
"HD Ticket",
|
|
32
|
+
filters={
|
|
33
|
+
"status": "Open",
|
|
34
|
+
"priority": rule.priority,
|
|
35
|
+
"opening_date": ("<", cutoff),
|
|
36
|
+
},
|
|
37
|
+
pluck="name",
|
|
38
|
+
)
|
|
39
|
+
for ticket_name in overdue:
|
|
40
|
+
_escalate(ticket_name, rule)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _escalate(ticket_name: str, rule) -> None:
|
|
44
|
+
ticket = frappe.get_doc("HD Ticket", ticket_name)
|
|
45
|
+
|
|
46
|
+
marker = f"Escalated by rule {rule.name}"
|
|
47
|
+
already = frappe.db.exists(
|
|
48
|
+
"Comment",
|
|
49
|
+
{
|
|
50
|
+
"reference_doctype": "HD Ticket",
|
|
51
|
+
"reference_name": ticket_name,
|
|
52
|
+
"content": ("like", f"%{marker}%"),
|
|
53
|
+
},
|
|
54
|
+
)
|
|
55
|
+
if already:
|
|
56
|
+
return
|
|
57
|
+
|
|
58
|
+
ticket.add_comment(
|
|
59
|
+
"Comment",
|
|
60
|
+
f"{marker}: open for more than {rule.hours_until_escalation}h.",
|
|
61
|
+
)
|
|
62
|
+
if rule.escalate_to:
|
|
63
|
+
_assign(ticket_name, rule.escalate_to)
|
|
64
|
+
frappe.db.commit()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _assign(ticket_name: str, user: str) -> None:
|
|
68
|
+
from frappe.desk.form.assign_to import add as assign_to
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
assign_to(
|
|
72
|
+
{
|
|
73
|
+
"assign_to": [user],
|
|
74
|
+
"doctype": "HD Ticket",
|
|
75
|
+
"name": ticket_name,
|
|
76
|
+
"description": "Escalated ticket (see comments).",
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
except frappe.exceptions.DuplicateEntryError:
|
|
80
|
+
pass # already assigned — the job re-ran, which is fine
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def close_stale_resolved_tickets() -> None:
|
|
84
|
+
"""Daily: close tickets that have sat in Resolved for more than 7 days."""
|
|
85
|
+
if not frappe.db.table_exists("HD Ticket"):
|
|
86
|
+
return
|
|
87
|
+
|
|
88
|
+
cutoff = add_to_date(now_datetime(), days=-7)
|
|
89
|
+
stale = frappe.get_all(
|
|
90
|
+
"HD Ticket",
|
|
91
|
+
filters={"status": "Resolved", "modified": ("<", cutoff)},
|
|
92
|
+
pluck="name",
|
|
93
|
+
)
|
|
94
|
+
for ticket_name in stale:
|
|
95
|
+
ticket = frappe.get_doc("HD Ticket", ticket_name)
|
|
96
|
+
ticket.status = "Closed"
|
|
97
|
+
ticket.save(ignore_permissions=True)
|
|
98
|
+
if stale:
|
|
99
|
+
frappe.db.commit()
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{% extends "templates/web.html" %}
|
|
2
|
+
|
|
3
|
+
{% block title %}Ticket Stats{% endblock %}
|
|
4
|
+
|
|
5
|
+
{% block page_content %}
|
|
6
|
+
<h1>Ticket Stats</h1>
|
|
7
|
+
|
|
8
|
+
{% if not stats.helpdesk_installed %}
|
|
9
|
+
<p>Frappe Helpdesk is not installed on this site, so there are no tickets to count.</p>
|
|
10
|
+
{% elif stats.total == 0 %}
|
|
11
|
+
<p>No tickets yet. Create one in the <a href="/helpdesk">Helpdesk</a> to see it counted here.</p>
|
|
12
|
+
{% else %}
|
|
13
|
+
<p>{{ stats.total }} ticket(s) in total.</p>
|
|
14
|
+
<table class="table table-bordered" style="max-width: 24rem">
|
|
15
|
+
<thead>
|
|
16
|
+
<tr><th>Status</th><th>Count</th></tr>
|
|
17
|
+
</thead>
|
|
18
|
+
<tbody>
|
|
19
|
+
{% for status, count in stats.by_status.items() %}
|
|
20
|
+
<tr><td>{{ status }}</td><td>{{ count }}</td></tr>
|
|
21
|
+
{% endfor %}
|
|
22
|
+
</tbody>
|
|
23
|
+
</table>
|
|
24
|
+
{% endif %}
|
|
25
|
+
|
|
26
|
+
<p class="text-muted">
|
|
27
|
+
Served by <code>ticketing/templates/pages/ticket_stats.py</code> — the same numbers are
|
|
28
|
+
available as JSON at <code>/api/method/ticketing.api.ticket_stats</code>.
|
|
29
|
+
</p>
|
|
30
|
+
{% endblock %}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Server-side context for the /ticket_stats portal page.
|
|
2
|
+
|
|
3
|
+
A file pair under templates/pages/ — <route>.py + <route>.html — becomes a
|
|
4
|
+
website route automatically. get_context runs on every request; whatever it
|
|
5
|
+
puts on `context` is available to the Jinja template.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from ticketing.api import ticket_stats
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_context(context):
|
|
12
|
+
context.no_cache = 1
|
|
13
|
+
context.stats = ticket_stats()
|
|
14
|
+
return context
|
|
File without changes
|
|
File without changes
|
package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Unit tests for Ticket Escalation Rule.
|
|
2
|
+
|
|
3
|
+
Run with `dude test` (wraps `bench run-tests --app ticketing`).
|
|
4
|
+
FrappeTestCase wraps every test in a transaction and rolls it back,
|
|
5
|
+
so tests never leak data into the site.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import frappe
|
|
9
|
+
from frappe.tests.utils import FrappeTestCase
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TestTicketEscalationRule(FrappeTestCase):
|
|
13
|
+
def make_rule(self, **overrides):
|
|
14
|
+
doc = frappe.get_doc(
|
|
15
|
+
{
|
|
16
|
+
"doctype": "Ticket Escalation Rule",
|
|
17
|
+
"rule_name": "Test escalation rule",
|
|
18
|
+
"priority": "High",
|
|
19
|
+
"hours_until_escalation": 4,
|
|
20
|
+
**overrides,
|
|
21
|
+
}
|
|
22
|
+
)
|
|
23
|
+
return doc
|
|
24
|
+
|
|
25
|
+
def test_valid_rule_is_saved(self):
|
|
26
|
+
rule = self.make_rule().insert()
|
|
27
|
+
self.assertEqual(rule.name, "Test escalation rule")
|
|
28
|
+
self.assertEqual(rule.is_enabled, 1)
|
|
29
|
+
|
|
30
|
+
def test_non_positive_hours_are_rejected(self):
|
|
31
|
+
rule = self.make_rule(hours_until_escalation=0)
|
|
32
|
+
self.assertRaises(frappe.ValidationError, rule.insert)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Desk form script — client-side view logic for Ticket Escalation Rule.
|
|
2
|
+
// Runs in the browser when the form is opened in the Desk UI.
|
|
3
|
+
// Reference: https://docs.frappe.io/framework/user/en/api/form
|
|
4
|
+
frappe.ui.form.on("Ticket Escalation Rule", {
|
|
5
|
+
refresh(frm) {
|
|
6
|
+
if (!frm.doc.is_enabled) {
|
|
7
|
+
frm.dashboard.set_headline(__("This rule is disabled and will never fire."));
|
|
8
|
+
}
|
|
9
|
+
if (frm.doc.workflow_state && frm.doc.workflow_state !== "Approved") {
|
|
10
|
+
frm.dashboard.set_headline(
|
|
11
|
+
__("Awaiting approval — only <b>Approved</b> rules escalate tickets."),
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
hours_until_escalation(frm) {
|
|
17
|
+
// Field-change handler: gentle client-side guardrail (the controller
|
|
18
|
+
// enforces the same rule server-side — never trust the client alone).
|
|
19
|
+
if (frm.doc.hours_until_escalation < 1) {
|
|
20
|
+
frappe.msgprint(__("Hours Until Escalation must be at least 1."));
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"actions": [],
|
|
3
|
+
"allow_rename": 1,
|
|
4
|
+
"autoname": "field:rule_name",
|
|
5
|
+
"creation": "2026-01-01 00:00:00.000000",
|
|
6
|
+
"doctype": "DocType",
|
|
7
|
+
"engine": "InnoDB",
|
|
8
|
+
"field_order": [
|
|
9
|
+
"rule_name",
|
|
10
|
+
"is_enabled",
|
|
11
|
+
"column_break_main",
|
|
12
|
+
"priority",
|
|
13
|
+
"rule_section",
|
|
14
|
+
"hours_until_escalation",
|
|
15
|
+
"escalate_to",
|
|
16
|
+
"description"
|
|
17
|
+
],
|
|
18
|
+
"fields": [
|
|
19
|
+
{
|
|
20
|
+
"fieldname": "rule_name",
|
|
21
|
+
"fieldtype": "Data",
|
|
22
|
+
"in_list_view": 1,
|
|
23
|
+
"label": "Rule Name",
|
|
24
|
+
"reqd": 1,
|
|
25
|
+
"unique": 1
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"default": "1",
|
|
29
|
+
"fieldname": "is_enabled",
|
|
30
|
+
"fieldtype": "Check",
|
|
31
|
+
"in_list_view": 1,
|
|
32
|
+
"label": "Enabled"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"fieldname": "column_break_main",
|
|
36
|
+
"fieldtype": "Column Break"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"default": "Medium",
|
|
40
|
+
"fieldname": "priority",
|
|
41
|
+
"fieldtype": "Select",
|
|
42
|
+
"in_list_view": 1,
|
|
43
|
+
"label": "Ticket Priority",
|
|
44
|
+
"options": "Low\nMedium\nHigh\nUrgent",
|
|
45
|
+
"reqd": 1
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"fieldname": "rule_section",
|
|
49
|
+
"fieldtype": "Section Break",
|
|
50
|
+
"label": "Escalation"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"default": "24",
|
|
54
|
+
"description": "Open tickets of the selected priority older than this many hours are escalated.",
|
|
55
|
+
"fieldname": "hours_until_escalation",
|
|
56
|
+
"fieldtype": "Int",
|
|
57
|
+
"label": "Hours Until Escalation",
|
|
58
|
+
"reqd": 1
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"description": "Ticket is assigned to this user when the rule fires.",
|
|
62
|
+
"fieldname": "escalate_to",
|
|
63
|
+
"fieldtype": "Link",
|
|
64
|
+
"label": "Escalate To",
|
|
65
|
+
"options": "User"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"fieldname": "description",
|
|
69
|
+
"fieldtype": "Small Text",
|
|
70
|
+
"label": "Description"
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"index_web_pages_for_search": 1,
|
|
74
|
+
"links": [],
|
|
75
|
+
"modified": "2026-01-01 00:00:00.000000",
|
|
76
|
+
"modified_by": "Administrator",
|
|
77
|
+
"module": "Ticketing",
|
|
78
|
+
"name": "Ticket Escalation Rule",
|
|
79
|
+
"naming_rule": "By fieldname",
|
|
80
|
+
"owner": "Administrator",
|
|
81
|
+
"permissions": [
|
|
82
|
+
{
|
|
83
|
+
"create": 1,
|
|
84
|
+
"delete": 1,
|
|
85
|
+
"email": 1,
|
|
86
|
+
"export": 1,
|
|
87
|
+
"print": 1,
|
|
88
|
+
"read": 1,
|
|
89
|
+
"report": 1,
|
|
90
|
+
"role": "System Manager",
|
|
91
|
+
"share": 1,
|
|
92
|
+
"write": 1
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"sort_field": "modified",
|
|
96
|
+
"sort_order": "DESC",
|
|
97
|
+
"states": [],
|
|
98
|
+
"track_changes": 1
|
|
99
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Controller for the Ticket Escalation Rule DocType.
|
|
2
|
+
|
|
3
|
+
The class name is the CamelCase DocType name; Frappe instantiates it for
|
|
4
|
+
every document of this type. Lifecycle hooks you can override include
|
|
5
|
+
validate, before_save, on_update, on_trash — see
|
|
6
|
+
https://docs.frappe.io/framework/user/en/basics/doctypes/controllers
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import frappe
|
|
10
|
+
from frappe import _
|
|
11
|
+
from frappe.model.document import Document
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TicketEscalationRule(Document):
|
|
15
|
+
def validate(self):
|
|
16
|
+
"""Runs on every save, before the document hits the database."""
|
|
17
|
+
if self.hours_until_escalation is not None and self.hours_until_escalation <= 0:
|
|
18
|
+
frappe.throw(_("Hours Until Escalation must be a positive number."))
|