Skip to content

Commit b83dcb3

Browse files
Merge pull request #2092 from RitvikSardana/attachments
fix: attachments
2 parents f22edac + 84af03f commit b83dcb3

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

desk/src/pages/TicketAgent.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ function updateTicket(fieldname: string, value: string) {
361361
auto: true,
362362
onSuccess: () => {
363363
isLoading.value = false;
364-
ticket.reload();
365364
createToast({
366365
title: "Ticket updated",
367366
icon: "check",

helpdesk/helpdesk/doctype/hd_ticket/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
def new(doc, attachments=[]):
1616
doc["doctype"] = "HD Ticket"
1717
doc["via_customer_portal"] = bool(frappe.session.user)
18+
doc["attachments"] = attachments
1819
d = frappe.get_doc(doc).insert()
1920
return d
2021

helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ def reply_via_agent(
571571
file_doc.attached_to_name = communication.name
572572
file_doc.attached_to_doctype = "Communication"
573573
file_doc.save(ignore_permissions=True)
574+
self.attach_file_with_ticket(file_doc.file_url)
575+
574576
_attachments.append({"file_url": file_doc.file_url})
575577

576578
reply_to_email = sender_email.email_id
@@ -617,6 +619,7 @@ def reply_via_agent(
617619
@frappe.whitelist()
618620
# flake8: noqa
619621
def create_communication_via_contact(self, message, attachments=[]):
622+
620623
if self.status == "Replied":
621624
self.status = "Open"
622625
log_ticket_activity(self.name, "set status to Open")
@@ -636,15 +639,22 @@ def create_communication_via_contact(self, message, attachments=[]):
636639
c.ignore_permissions = True
637640
c.ignore_mandatory = True
638641
c.save(ignore_permissions=True)
639-
640-
if not len(attachments):
642+
_attachments = self.get("attachments") or attachments or []
643+
if not len(_attachments):
641644
return
642645
QBFile = frappe.qb.DocType("File")
643-
condition_name = [QBFile.name == i["name"] for i in attachments]
646+
condition_name = [QBFile.name == i["name"] for i in _attachments]
644647
frappe.qb.update(QBFile).set(QBFile.attached_to_name, c.name).set(
645648
QBFile.attached_to_doctype, "Communication"
646649
).where(Criterion.any(condition_name)).run()
647650

651+
# attach files to ticket
652+
file_urls = frappe.get_all(
653+
"File", filters={"attached_to_name": c.name}, pluck="file_url"
654+
)
655+
for url in file_urls:
656+
self.attach_file_with_ticket(url)
657+
648658
@frappe.whitelist()
649659
def mark_seen(self):
650660
self.add_view()
@@ -750,6 +760,13 @@ def on_communication_update(self, c):
750760
# Save the ticket, allowing for hooks to run.
751761
self.save()
752762

763+
def attach_file_with_ticket(self, file_url):
764+
file_doc = frappe.new_doc("File")
765+
file_doc.attached_to_name = self.name
766+
file_doc.attached_to_doctype = "HD Ticket"
767+
file_doc.file_url = file_url
768+
file_doc.save(ignore_permissions=True)
769+
753770
@staticmethod
754771
def default_list_data(show_customer_portal_fields=False):
755772
columns = [

0 commit comments

Comments
 (0)