From 83fcaf84ac6289a619be7c6d2d1d98fe568ef183 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Thu, 18 Dec 2025 21:13:01 +0100 Subject: [PATCH] fix: correct order sync_status and historical import display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix historical import to also update sync_status when it's out of sync with letzshop_state (e.g., confirmed orders showing as pending) - Fix frontend to read stats from response.statistics nested object - Orders with matching letzshop_state but wrong sync_status now get fixed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- app/services/letzshop/order_service.py | 16 ++++++++++++++-- static/admin/js/marketplace-letzshop.js | 6 ++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/services/letzshop/order_service.py b/app/services/letzshop/order_service.py index e6a07dfe..781176be 100644 --- a/app/services/letzshop/order_service.py +++ b/app/services/letzshop/order_service.py @@ -622,11 +622,23 @@ class LetzshopOrderService: if existing_order: # Check if we need to update (e.g., state changed) - if existing_order.letzshop_state != shipment.get("state"): + shipment_state = shipment.get("state") + if existing_order.letzshop_state != shipment_state: self.update_order_from_shipment(existing_order, shipment) stats["updated"] += 1 else: - stats["skipped"] += 1 + # Also fix sync_status if it's out of sync with letzshop_state + state_mapping = { + "unconfirmed": "pending", + "confirmed": "confirmed", + "declined": "rejected", + } + expected_sync_status = state_mapping.get(shipment_state, "confirmed") + if existing_order.sync_status != expected_sync_status: + existing_order.sync_status = expected_sync_status + stats["updated"] += 1 + else: + stats["skipped"] += 1 else: # Create new order self.create_order(vendor_id, shipment) diff --git a/static/admin/js/marketplace-letzshop.js b/static/admin/js/marketplace-letzshop.js index 2dfa8216..63c8d312 100644 --- a/static/admin/js/marketplace-letzshop.js +++ b/static/admin/js/marketplace-letzshop.js @@ -469,8 +469,10 @@ function adminMarketplaceLetzshop() { `/admin/letzshop/vendors/${this.selectedVendor.id}/import-history?state=confirmed` ); - this.historicalImportResult = response; - this.successMessage = `Historical import complete: ${response.imported} imported, ${response.updated} updated`; + // Stats are nested under 'statistics' key + this.historicalImportResult = response.statistics || response; + const stats = this.historicalImportResult; + this.successMessage = `Historical import complete: ${stats.imported} imported, ${stats.updated} updated`; marketplaceLetzshopLog.info('Historical import result:', response);