feat: add export job tracking to Letzshop jobs tab
- Export operations now create LetzshopSyncLog entries with type 'product_export' - Added log_export method to LetzshopExportService (follows architecture rules) - Updated list_letzshop_jobs to include export jobs - Added export filter option back to jobs dropdown - Export jobs display with blue badge and cloud-upload icon 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -390,6 +390,7 @@ def export_vendor_products_letzshop_to_folder(
|
||||
JSON with export status and file paths
|
||||
"""
|
||||
import os
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path as FilePath
|
||||
|
||||
from app.services.letzshop_export_service import letzshop_export_service
|
||||
@@ -398,12 +399,17 @@ def export_vendor_products_letzshop_to_folder(
|
||||
|
||||
include_inactive = request.include_inactive if request else False
|
||||
|
||||
# Track export start time
|
||||
started_at = datetime.now(UTC)
|
||||
|
||||
# Create export directory
|
||||
export_dir = FilePath(f"exports/letzshop/{vendor.vendor_code.lower()}")
|
||||
export_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
exported_files = []
|
||||
languages = ["fr", "de", "en"]
|
||||
total_records = 0
|
||||
failed_count = 0
|
||||
|
||||
for lang in languages:
|
||||
try:
|
||||
@@ -420,6 +426,11 @@ def export_vendor_products_letzshop_to_folder(
|
||||
with open(filepath, "w", encoding="utf-8") as f:
|
||||
f.write(csv_content)
|
||||
|
||||
# Count lines (minus header)
|
||||
line_count = csv_content.count("\n")
|
||||
if line_count > 0:
|
||||
total_records = max(total_records, line_count - 1)
|
||||
|
||||
exported_files.append({
|
||||
"language": lang,
|
||||
"filename": filename,
|
||||
@@ -427,11 +438,27 @@ def export_vendor_products_letzshop_to_folder(
|
||||
"size_bytes": os.path.getsize(filepath),
|
||||
})
|
||||
except Exception as e:
|
||||
failed_count += 1
|
||||
exported_files.append({
|
||||
"language": lang,
|
||||
"error": str(e),
|
||||
})
|
||||
|
||||
# Log the export operation via service
|
||||
completed_at = datetime.now(UTC)
|
||||
letzshop_export_service.log_export(
|
||||
db=db,
|
||||
vendor_id=vendor.id,
|
||||
started_at=started_at,
|
||||
completed_at=completed_at,
|
||||
records_processed=total_records,
|
||||
languages_succeeded=len(languages) - failed_count,
|
||||
languages_failed=failed_count,
|
||||
triggered_by=f"admin:{current_admin.id}",
|
||||
error_details={"files": exported_files} if failed_count > 0 else None,
|
||||
)
|
||||
db.commit()
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"message": f"Exported {len([f for f in exported_files if 'error' not in f])} language(s) to {export_dir}",
|
||||
|
||||
Reference in New Issue
Block a user