From d9b76312d976866090bc41d91ee9ddfe598db0f3 Mon Sep 17 00:00:00 2001 From: ruuushhh <66899387+ruuushhh@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:43:22 +0530 Subject: [PATCH] Fix Attachments (#547) --- apps/netsuite/tasks.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/netsuite/tasks.py b/apps/netsuite/tasks.py index bfee07c7..a117cc47 100644 --- a/apps/netsuite/tasks.py +++ b/apps/netsuite/tasks.py @@ -371,11 +371,21 @@ def upload_attachments_and_update_export(expenses: List[Expense], task_log: Task for expense in expenses: if expense.file_ids and len(expense.file_ids): - # Grabbing 1st attachment since we can upload only 1 attachment per expense - payload = [{'id': expense.file_ids[0]}] - attachments = platform.files.bulk_generate_file_urls(payload) + files_list = [] + attachments = [] + + file_ids = expense.file_ids + + for file_id in file_ids: + files_list.append({'id': file_id}) - attachment = attachments[0] if len(attachments) else None + attachments = platform.files.bulk_generate_file_urls(files_list) + + # Filter HTML attachments + attachments = list(filter(lambda attachment: attachment['content_type'] != 'text/html', attachments)) + + # Grabbing 1st attachment since we can upload only 1 attachment per expense + attachment = attachments[0] if len(attachments) else None if attachment: netsuite_connection.connection.files.post({