From e626976f382abf075a99c82aca5e3fcfce6882c8 Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Mon, 11 Aug 2025 20:47:30 +0000 Subject: [PATCH] Automatically mark orders as delivered when deliveries are updated or validated Implement automatic synchronization to update associated orders to 'delivered' status when a delivery's status is set to 'delivered' or when a delivery is validated, simplifying the order management workflow. Replit-Commit-Author: Agent Replit-Commit-Session-Id: a8a78c07-e900-425c-a577-5b4c5894379d Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/a8a78c07-e900-425c-a577-5b4c5894379d/KuIk8gU --- ...r-user-adm-1754945126235_1754945126235.txt | 202 ++++++++++++++++++ server/routes.ts | 24 +++ 2 files changed, 226 insertions(+) create mode 100644 attached_assets/Pasted--getUserWithGroups-called-for-user-admin-local-Querying-user-groups-for-user-adm-1754945126235_1754945126235.txt diff --git a/attached_assets/Pasted--getUserWithGroups-called-for-user-admin-local-Querying-user-groups-for-user-adm-1754945126235_1754945126235.txt b/attached_assets/Pasted--getUserWithGroups-called-for-user-admin-local-Querying-user-groups-for-user-adm-1754945126235_1754945126235.txt new file mode 100644 index 0000000..f4c4e12 --- /dev/null +++ b/attached_assets/Pasted--getUserWithGroups-called-for-user-admin-local-Querying-user-groups-for-user-adm-1754945126235_1754945126235.txt @@ -0,0 +1,202 @@ + + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +Deliveries API called with: { + + startDate: undefined, + + endDate: undefined, + + storeId: undefined, + + withBL: undefined, + + userRole: 'admin' + +} + +Admin filtering deliveries with groupIds: undefined + +Fetching all deliveries + +Deliveries returned: 80 items + +GET /api/deliveries 304 in 44ms + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +📄 SPA: Serving index.html for /[object%20Object] + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +📄 SPA: Serving index.html for /[object%20Object] + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +📄 SPA: Serving index.html for /[object%20Object] + +🔍 getUserWithGroups called for user: admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +Orders API called with: { + + startDate: '2025-08-01', + + endDate: '2025-08-31', + + storeId: '1', + + userRole: 'admin' + +} + +Admin filtering with groupIds: [ 1 ] + +Fetching orders by date range: 2025-08-01 to 2025-08-31 + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +Deliveries API called with: { + + startDate: '2025-08-01', + + endDate: '2025-08-31', + + storeId: '1', + + withBL: undefined, + + userRole: 'admin' + +} + +Admin filtering deliveries with groupIds: [ 1 ] + +Fetching deliveries by date range: 2025-08-01 to 2025-08-31 + +Orders returned: 9 items + +GET /api/orders 304 in 23ms + +Deliveries returned: 20 items + +GET /api/deliveries 304 in 36ms + diff --git a/server/routes.ts b/server/routes.ts index 70fa5b5..eb21026 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -690,6 +690,18 @@ export async function registerRoutes(app: Express): Promise { const data = insertDeliverySchema.partial().parse(req.body); const updatedDelivery = await storage.updateDelivery(id, data); + + // SYNCHRONISATION AUTOMATIQUE : Si livraison devient "delivered", marquer la commande associée comme "delivered" + if (data.status === 'delivered' && updatedDelivery.orderId) { + try { + console.log(`🔄 Auto-sync: Delivery #${id} marked as delivered, updating order #${updatedDelivery.orderId}`); + await storage.updateOrder(updatedDelivery.orderId, { status: 'delivered' }); + console.log(`✅ Auto-sync: Order #${updatedDelivery.orderId} automatically marked as delivered`); + } catch (error) { + console.error(`❌ Auto-sync failed for order #${updatedDelivery.orderId}:`, error); + } + } + res.json(updatedDelivery); } catch (error) { console.error("Error updating delivery:", error); @@ -828,6 +840,18 @@ export async function registerRoutes(app: Express): Promise { } await storage.validateDelivery(id, blData); + + // SYNCHRONISATION AUTOMATIQUE : Quand validation, marquer la commande associée comme "delivered" + if (delivery.orderId) { + try { + console.log(`🔄 Auto-sync: Delivery #${id} validated, updating order #${delivery.orderId} to delivered`); + await storage.updateOrder(delivery.orderId, { status: 'delivered' }); + console.log(`✅ Auto-sync: Order #${delivery.orderId} automatically marked as delivered`); + } catch (error) { + console.error(`❌ Auto-sync failed for order #${delivery.orderId}:`, error); + } + } + res.json({ message: "Delivery validated successfully" }); } catch (error) { console.error("Error validating delivery:", error);