Improve automatic data filling for credit notes with better error handling

Add null and undefined checks to 'Avoirs' page for invoice amount auto-filling and wrap mutation in try-catch block.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869/H30E1Dv
This commit is contained in:
michaelschal committed 2025-09-08 18:56:43 +00:00
1 parent 559d26aa38
commit cecd2e6031
2 files changed
+20 -15

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 KiB

+20 -15
View File
@@ -442,22 +442,27 @@ export default function Avoirs() {
})); }));
// Auto-remplissage si facture trouvée et montant disponible // Auto-remplissage si facture trouvée et montant disponible
if (result.exists && result.invoiceAmount) { if (result?.exists && result?.invoiceAmount !== undefined && result?.invoiceAmount !== null) {
// Auto-remplir le montant dans l'avoir via API // Auto-remplir le montant dans l'avoir via API
const avoir = avoirs.find(a => a.id === variables.avoirId); const avoir = avoirs?.find(a => a?.id === variables.avoirId);
if (avoir) { if (avoir && avoir.supplierId && avoir.groupId) {
editAvoirMutation.mutate({ try {
id: variables.avoirId, editAvoirMutation.mutate({
data: { id: variables.avoirId,
supplierId: avoir.supplierId, data: {
groupId: avoir.groupId, supplierId: avoir.supplierId,
invoiceReference: avoir.invoiceReference || "", groupId: avoir.groupId,
amount: result.invoiceAmount, // Auto-remplissage du montant invoiceReference: avoir.invoiceReference || "",
comment: avoir.comment || "", amount: result.invoiceAmount, // Auto-remplissage du montant
commercialProcessed: avoir.commercialProcessed, comment: avoir.comment || "",
status: avoir.status as "En attente de demande" | "Demandé" | "Reçu", commercialProcessed: avoir.commercialProcessed || false,
} status: avoir.status as "En attente de demande" | "Demandé" | "Reçu",
}); }
});
} catch (autoFillError) {
console.error('Erreur auto-remplissage montant:', autoFillError);
// Ne pas faire échouer la vérification si l'auto-remplissage échoue
}
} }
} }