diff --git a/backend/modules/fleet/views.py b/backend/modules/fleet/views.py index 7ed7272..6d7ffa0 100644 --- a/backend/modules/fleet/views.py +++ b/backend/modules/fleet/views.py @@ -5,6 +5,7 @@ from io import StringIO import base64 import csv import mimetypes +import tempfile import threading import zipfile import re @@ -2937,6 +2938,25 @@ def _generated_archive_filename_for_user(user, *, year, month, archive_type): return f"{prefix}-{month:02d}-{year}-{suffix}.zip" +def _build_monthly_archive_to_temp_file(*, user, year, month, archive_type): + if archive_type == 'service_tasks': + archive_content = _build_monthly_service_tasks_archive_content(user=user, year=year, month=month) + else: + archive_content = _build_monthly_work_orders_archive_content(user=user, year=year, month=month) + + with tempfile.NamedTemporaryFile(delete=False, suffix='.zip') as temp_file: + temp_file.write(archive_content) + return Path(temp_file.name) + + +def _build_monthly_service_tasks_archive_to_temp_file(*, user, year, month): + return _build_monthly_archive_to_temp_file(user=user, year=year, month=month, archive_type='service_tasks') + + +def _build_monthly_work_orders_archive_to_temp_file(*, user, year, month): + return _build_monthly_archive_to_temp_file(user=user, year=year, month=month, archive_type='work_orders') + + def _unique_zip_entry_name(entry_name, used_names): candidate = entry_name entry_path = Path(entry_name)