Enable automatic delivery validation for designated suppliers

Add automatic delivery validation logic to the reconciliation process, enabling auto-validation for deliveries from suppliers configured for automatic reconciliation when the delivery status is 'delivered' and a BL number is present. Includes a new method to retrieve supplier details and updates to documentation.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: b163d4c0-de5e-4f4e-a9c0-aed4c7049718
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/b163d4c0-de5e-4f4e-a9c0-aed4c7049718/FyjZ5oh
This commit is contained in:
michaelschal committed 2025-08-12 10:16:28 +00:00
1 parent f7891cda01
commit c79ac79a91
3 files changed
+32

No files matched your search

+25
View File
@@ -702,6 +702,31 @@ export async function registerRoutes(app: Express): Promise<Server> {
console.error(`❌ Auto-sync failed for order #${updatedDelivery.orderId}:`, error);
}
}
// AUTO-VALIDATION RAPPROCHEMENT AUTOMATIQUE : Si fournisseur en mode automatique, livraison delivered + BL → auto-valider
if (data.status === 'delivered' || data.blNumber) {
try {
// Récupérer le fournisseur pour vérifier le mode automatique
const supplier = await storage.getSupplier(updatedDelivery.supplierId);
if (supplier?.automaticReconciliation &&
updatedDelivery.status === 'delivered' &&
updatedDelivery.blNumber) {
console.log(`🤖 Auto-reconciliation: Delivery #${id} from automatic supplier ${supplier.name}, auto-validating...`);
// Auto-valider le rapprochement
await storage.updateDelivery(id, {
reconciled: true,
validatedAt: new Date()
});
console.log(`✅ Auto-reconciliation: Delivery #${id} automatically validated for supplier ${supplier.name}`);
}
} catch (error) {
console.error(`❌ Auto-reconciliation failed for delivery #${id}:`, error);
}
}
res.json(updatedDelivery);
} catch (error) {
+5
View File
@@ -470,6 +470,11 @@ export class DatabaseStorage implements IStorage {
return await db.select().from(suppliers).orderBy(suppliers.name);
}
async getSupplier(id: number): Promise<Supplier | undefined> {
const [supplier] = await db.select().from(suppliers).where(eq(suppliers.id, id));
return supplier;
}
async createSupplier(supplier: InsertSupplier): Promise<Supplier> {
const [newSupplier] = await db.insert(suppliers).values(supplier).returning();
return newSupplier;