Skip to content

Commit

Permalink
chore: hooks: use on_communication_update
Browse files Browse the repository at this point in the history
  • Loading branch information
ssiyad committed Oct 11, 2023
1 parent 28e402e commit 846846a
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 @@ -720,6 +720,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):

Check warning on line 727 in helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py#L727

Added line #L727 was not covered by tests
# If communication is outgoing, then it is a reply from agent.
if c.sent_or_received == "Sent":
self.status = "Replied"

Check warning on line 730 in helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py#L729-L730

Added lines #L729 - L730 were not covered by tests
# 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

Check warning on line 733 in helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py#L733

Added line #L733 was not covered by tests
# Save the ticket, allowing for hooks to run.
self.save()

Check warning on line 735 in helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py

View check run for this annotation

Codecov / codecov/patch

helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py#L735

Added line #L735 was not covered by tests


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 @@ -24,9 +24,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 846846a

Please sign in to comment.