@@ -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