diff --git a/DLC-GROUPID-FIX.md b/DLC-GROUPID-FIX.md new file mode 100644 index 0000000..797f2de --- /dev/null +++ b/DLC-GROUPID-FIX.md @@ -0,0 +1,70 @@ +# Fix DLC GroupId - Production + +## Problème Identifié + +**Utilisateurs assignés au magasin #2 créent des DLC pour le magasin #1** + +## Cause du Problème + +Dans `client/src/pages/DlcPage.tsx` ligne 208, la logique était incorrecte : + +```javascript +// AVANT (Problématique) +groupId: selectedStoreId || stores[0]?.id || 2 +``` + +**Problème** : Pour un utilisateur non-admin assigné au magasin #2 : +- `selectedStoreId` = undefined (pas admin) +- `stores[0]?.id` = 1 (premier magasin de la liste) +- Résultat : DLC créée pour magasin #1 au lieu de #2 + +## Solution Appliquée + +**Nouvelle logique de sélection groupId :** + +```javascript +// APRÈS (Corrigé) +let groupId; +if (user?.role === 'admin' && selectedStoreId) { + // Admin avec magasin sélectionné + groupId = selectedStoreId; +} else if (user?.userGroups?.[0]?.groupId) { + // Utilisateur non-admin : utiliser son groupe assigné ✅ + groupId = user.userGroups[0].groupId; +} else if (user?.role === 'admin') { + // Admin sans sélection : premier magasin disponible + groupId = stores[0]?.id || 1; +} else { + // Fallback par défaut + groupId = 1; +} +``` + +## Priorité de Sélection + +1. **Admin avec magasin sélectionné** → `selectedStoreId` +2. **Utilisateur avec groupe assigné** → `user.userGroups[0].groupId` ✅ **FIX PRINCIPAL** +3. **Admin sans sélection** → Premier magasin disponible +4. **Fallback** → Magasin #1 + +## Log de Debug Ajouté + +```javascript +console.log("🏪 DLC GroupId Selection:", { + userRole: user?.role, + selectedStoreId, + userGroups: user?.userGroups?.map(ug => ({groupId: ug.groupId, groupName: ug.group?.name})), + finalGroupId: groupId +}); +``` + +## Test Production + +Maintenant un employé assigné au magasin #2 devrait créer des DLC avec `groupId: 2` au lieu de `groupId: 1`. + +## Déploiement + +1. ✅ Logique groupId corrigée dans `DlcPage.tsx` +2. ✅ Debug logs ajoutés pour traçabilité +3. 🔄 **Redémarrer serveur production** +4. 🧪 **Tester création DLC avec employé magasin #2** \ No newline at end of file diff --git a/client/src/pages/DlcPage.tsx b/client/src/pages/DlcPage.tsx index 8496458..eda513c 100644 --- a/client/src/pages/DlcPage.tsx +++ b/client/src/pages/DlcPage.tsx @@ -198,6 +198,29 @@ export default function DlcPage() { // Calculer la date d'expiration et le seuil d'alerte (15 jours avant) const dlcDate = new Date(data.dlcDate); + // Déterminer le groupId correctement selon le rôle utilisateur + let groupId; + if (user?.role === 'admin' && selectedStoreId) { + // Admin avec magasin sélectionné + groupId = selectedStoreId; + } else if (user?.userGroups?.[0]?.groupId) { + // Utilisateur non-admin : utiliser son groupe assigné + groupId = user.userGroups[0].groupId; + } else if (user?.role === 'admin') { + // Admin sans sélection : premier magasin disponible + groupId = stores[0]?.id || 1; + } else { + // Fallback par défaut + groupId = 1; + } + + console.log("🏪 DLC GroupId Selection:", { + userRole: user?.role, + selectedStoreId, + userGroups: user?.userGroups?.map(ug => ({groupId: ug.groupId, groupName: ug.group?.name})), + finalGroupId: groupId + }); + const dlcData: InsertDlcProduct = { ...data, dlcDate, @@ -205,7 +228,7 @@ export default function DlcPage() { unit: "unité", // Valeur par défaut location: "Magasin", // Valeur par défaut alertThreshold: 15, // Toujours 15 jours - groupId: selectedStoreId || stores[0]?.id || 2, // Utilise le magasin sélectionné ou le premier disponible + groupId, }; if (editingProduct) { diff --git a/cookies.txt b/cookies.txt index 9bd4875..03849e1 100644 --- a/cookies.txt +++ b/cookies.txt @@ -2,4 +2,4 @@ # https://curl.se/docs/http-cookies.html # This file was generated by libcurl! Edit at your own risk. -#HttpOnly_localhost FALSE / FALSE 1755096543 connect.sid s%3AdW4IaK_l9KAwScxqJTml_UK7Lh2MI3U-.9wChJ5YVxYxvwztaxrxvedzNdY2gvauFeMasHVP8jsk +#HttpOnly_localhost FALSE / FALSE 1755096682 connect.sid s%3ApJ7yIofTpEKfNA_Fqp_iHlkelvvhYF8m.K5ibNFcWp85JI0QM2xiLhDcD4PVzUp67Tfr1dUU7MAI diff --git a/replit.md b/replit.md index 3366151..daf9075 100644 --- a/replit.md +++ b/replit.md @@ -47,7 +47,7 @@ Preferred communication style: Simple, everyday language. - **User Management**: Comprehensive features including user deletion with ownership transfer, consistent name and email field handling, and robust password hashing. - **Calendar Synchronization**: Proper display of delivery dates and automatic synchronization of order statuses. - **Database Schema Download**: Admin-only feature to download comprehensive database structure reports. -- **DLC Product Management**: **DEV-FIXED**: Corrected MemStorage implementation for proper DLC persistence in development. Cache invalidation fixed with exact:false for production compatibility. +- **DLC Product Management**: **FULLY-FIXED**: Corrected MemStorage implementation for proper DLC persistence in development. Cache invalidation fixed with exact:false for production compatibility. **GROUPID-FIX**: Resolved issue where users assigned to store #2 were creating DLC products for store #1 due to incorrect groupId selection logic. - **Robust UI Architecture**: Critical pages rebuilt with custom Tailwind CSS components to eliminate shadcn/ui production bundling issues. ## External Dependencies