Skip to content

Commit

Permalink
Merge pull request #2092 from RitvikSardana/attachments
Browse files Browse the repository at this point in the history
fix: attachments
  • Loading branch information
RitvikSardana authored Dec 18, 2024
2 parents f22edac + 84af03f commit b83dcb3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 0 additions & 1 deletion desk/src/pages/TicketAgent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ function updateTicket(fieldname: string, value: string) {
auto: true,
onSuccess: () => {
isLoading.value = false;
ticket.reload();
createToast({
title: "Ticket updated",
icon: "check",
Expand Down
1 change: 1 addition & 0 deletions helpdesk/helpdesk/doctype/hd_ticket/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
def new(doc, attachments=[]):
doc["doctype"] = "HD Ticket"
doc["via_customer_portal"] = bool(frappe.session.user)
doc["attachments"] = attachments
d = frappe.get_doc(doc).insert()
return d

Expand Down
23 changes: 20 additions & 3 deletions helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ def reply_via_agent(
file_doc.attached_to_name = communication.name
file_doc.attached_to_doctype = "Communication"
file_doc.save(ignore_permissions=True)
self.attach_file_with_ticket(file_doc.file_url)

_attachments.append({"file_url": file_doc.file_url})

reply_to_email = sender_email.email_id
Expand Down Expand Up @@ -617,6 +619,7 @@ def reply_via_agent(
@frappe.whitelist()
# flake8: noqa
def create_communication_via_contact(self, message, attachments=[]):

if self.status == "Replied":
self.status = "Open"
log_ticket_activity(self.name, "set status to Open")
Expand All @@ -636,15 +639,22 @@ def create_communication_via_contact(self, message, attachments=[]):
c.ignore_permissions = True
c.ignore_mandatory = True
c.save(ignore_permissions=True)

if not len(attachments):
_attachments = self.get("attachments") or attachments or []
if not len(_attachments):
return
QBFile = frappe.qb.DocType("File")
condition_name = [QBFile.name == i["name"] for i in attachments]
condition_name = [QBFile.name == i["name"] for i in _attachments]
frappe.qb.update(QBFile).set(QBFile.attached_to_name, c.name).set(
QBFile.attached_to_doctype, "Communication"
).where(Criterion.any(condition_name)).run()

# attach files to ticket
file_urls = frappe.get_all(
"File", filters={"attached_to_name": c.name}, pluck="file_url"
)
for url in file_urls:
self.attach_file_with_ticket(url)

@frappe.whitelist()
def mark_seen(self):
self.add_view()
Expand Down Expand Up @@ -750,6 +760,13 @@ def on_communication_update(self, c):
# Save the ticket, allowing for hooks to run.
self.save()

def attach_file_with_ticket(self, file_url):
file_doc = frappe.new_doc("File")
file_doc.attached_to_name = self.name
file_doc.attached_to_doctype = "HD Ticket"
file_doc.file_url = file_url
file_doc.save(ignore_permissions=True)

@staticmethod
def default_list_data(show_customer_portal_fields=False):
columns = [
Expand Down

0 comments on commit b83dcb3

Please sign in to comment.