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
This commit is contained in:
michaelschal committed 2025-08-11 20:47:30 +00:00
1 parent 213208d48f
commit e626976f38
2 files changed
+226

No files matched your search

@@ -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
+24
View File
@@ -690,6 +690,18 @@ export async function registerRoutes(app: Express): Promise<Server> {
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<Server> {
}
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);