fix(reconciliation): auto-reconcile deliveries from automatic suppliers on validation

POST /api/deliveries/:id/validate never set reconciled=true for suppliers in
automatic reconciliation mode, so their deliveries showed in neither the
Manuels tab (auto suppliers excluded) nor Validées (reconciled=false).

- validate endpoint now marks reconciled + validatedAt for auto suppliers
- Validées tab includes all deliveries from auto suppliers
- migration backfills reconciled for existing delivered deliveries with BL

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Opus 5.5 committed 2026-10-09 09:18:43 +02:00
1 parent 944d99733c
commit 2274c9bb4a
3 files changed
+41 -1

No files matched your search

+15
View File
@@ -2556,6 +2556,21 @@ export async function registerRoutes(app: Express): Promise<Server> {
await storage.validateDelivery(id, blData);
// AUTO-VALIDATION RAPPROCHEMENT : fournisseur en mode automatique → rapprochement validé directement
try {
// Fournisseur déjà joint à la livraison
const supplier = delivery.supplier;
if (supplier?.automaticReconciliation) {
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);
}
// MISE À JOUR DU CACHE : Marquer le cache comme permanent pour cette livraison validée
try {
if (delivery.invoiceReference && delivery.invoiceReference.trim()) {