Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: attachments #2092

Merged
merged 9 commits into from
Dec 18, 2024
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
Loading