From 49523fe6fe8c3d2af2b244e9f0604a180e226191 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Sat, 20 Dec 2025 13:18:07 +0100 Subject: [PATCH] fix: add historical import jobs to unified jobs list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Historical import jobs were not appearing in the recent jobs list because list_letzshop_jobs() only queried marketplace_import_jobs and letzshop_sync_logs. Changes: - Add LetzshopHistoricalImportJob query to list_letzshop_jobs() - Add current_phase and error_message fields to LetzshopJobItem schema - Fixed stuck job 8 (marked as failed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- app/services/letzshop/order_service.py | 35 ++++++++++++++++++++++++-- models/schema/letzshop.py | 11 ++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/services/letzshop/order_service.py b/app/services/letzshop/order_service.py index 2b98a294..632bce2e 100644 --- a/app/services/letzshop/order_service.py +++ b/app/services/letzshop/order_service.py @@ -556,11 +556,42 @@ class LetzshopOrderService: """ List unified Letzshop-related jobs for a vendor. - Combines product imports from marketplace_import_jobs and - order syncs from letzshop_sync_logs. + Combines product imports, historical order imports, and order syncs. """ jobs = [] + # Historical order imports from letzshop_historical_import_jobs + if job_type in (None, "historical_import"): + hist_query = self.db.query(LetzshopHistoricalImportJob).filter( + LetzshopHistoricalImportJob.vendor_id == vendor_id, + ) + if status: + hist_query = hist_query.filter( + LetzshopHistoricalImportJob.status == status + ) + + hist_jobs = hist_query.order_by( + LetzshopHistoricalImportJob.created_at.desc() + ).all() + + for job in hist_jobs: + jobs.append( + { + "id": job.id, + "type": "historical_import", + "status": job.status, + "created_at": job.created_at, + "started_at": job.started_at, + "completed_at": job.completed_at, + "records_processed": job.orders_processed or 0, + "records_succeeded": (job.orders_imported or 0) + + (job.orders_updated or 0), + "records_failed": job.orders_skipped or 0, + "current_phase": job.current_phase, + "error_message": job.error_message, + } + ) + # Product imports from marketplace_import_jobs if job_type in (None, "import"): import_query = self.db.query(MarketplaceImportJob).filter( diff --git a/models/schema/letzshop.py b/models/schema/letzshop.py index 73e1807c..72fdba00 100644 --- a/models/schema/letzshop.py +++ b/models/schema/letzshop.py @@ -397,10 +397,12 @@ class LetzshopVendorListResponse(BaseModel): class LetzshopJobItem(BaseModel): - """Schema for a unified job item (import, export, or order sync).""" + """Schema for a unified job item (import, export, order sync, or historical import).""" id: int - type: str = Field(..., description="Job type: import, export, or order_sync") + type: str = Field( + ..., description="Job type: import, export, order_sync, or historical_import" + ) status: str = Field(..., description="Job status") created_at: datetime started_at: datetime | None = None @@ -408,6 +410,11 @@ class LetzshopJobItem(BaseModel): records_processed: int = 0 records_succeeded: int = 0 records_failed: int = 0 + # Historical import specific fields + current_phase: str | None = Field( + None, description="Current phase for historical imports" + ) + error_message: str | None = Field(None, description="Error message if failed") class LetzshopJobsListResponse(BaseModel):