Skip to content

Commit

Permalink
chore: hooks: use on_communication_update (frappe#1594)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssiyad authored and rtdany10 committed Oct 12, 2023
1 parent 771c3af commit 8adbf67
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
14 changes: 14 additions & 0 deletions helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,20 @@ def apply_sla(self):
sla = frappe.get_doc("HD Service Level Agreement", self.sla)
sla.apply(self)

# `on_communication_update` is a special method exposed from `Communication` doctype.
# It is called when a communication is updated. Beware of changes as this effectively
# is an external dependency. Refer `communication.py` of Frappe framework for more.
# Since this is called from communication itself, `c` is the communication doc.
def on_communication_update(self, c):
# If communication is outgoing, then it is a reply from agent.
if c.sent_or_received == "Sent":
self.status = "Replied"
# Fetch description from communication if not set already. This might not be needed
# anymore as a communication is created when a ticket is created.
self.description = self.description or c.content
# Save the ticket, allowing for hooks to run.
self.save()


def has_permission(doc):
user = frappe.session.user
Expand Down
23 changes: 0 additions & 23 deletions helpdesk/helpdesk/hooks/communication.py

This file was deleted.

3 changes: 0 additions & 3 deletions helpdesk/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
]

doc_events = {
"Communication": {
"after_insert": "helpdesk.helpdesk.hooks.communication.after_insert",
},
"Contact": {
"before_insert": "helpdesk.helpdesk.hooks.contact.before_insert",
},
Expand Down

0 comments on commit 8adbf67

Please sign in to comment.