From 9d27066da17036b952cc15986c0f05e73b2665ef Mon Sep 17 00:00:00 2001 From: acazares Date: Wed, 11 Feb 2026 20:37:10 -0600 Subject: [PATCH] Remove unnecessary console logs and improve code readability across multiple components --- .../export/manifest/manifest-form.svelte | 41 ++-------- .../modales/currency-selector-dialog.svelte | 9 +-- .../dashboard/goods/parts/partForm.svelte | 18 ++--- .../invoices/create-edit-dialog.svelte | 76 ++++++------------- .../edit/items/fa/country-dialog.svelte | 5 +- .../items/fa/tariff-fraction-dialog.svelte | 6 +- .../items/fa/unit-of-measure-dialog.svelte | 3 +- .../invoices/edit/others-tab-form.svelte | 9 --- .../routes/dashboard/admin/roles/+page.svelte | 9 --- .../doda/edit/[[id]]/+page.svelte | 10 --- .../dashboard/invoices/edit/[id]/+page.svelte | 12 ++- .../routes/dashboard/pedimentos/+page.svelte | 10 +-- 12 files changed, 57 insertions(+), 151 deletions(-) diff --git a/frontend/src/lib/components/dashboard/export/manifest/manifest-form.svelte b/frontend/src/lib/components/dashboard/export/manifest/manifest-form.svelte index 9a57d055..fe373b22 100644 --- a/frontend/src/lib/components/dashboard/export/manifest/manifest-form.svelte +++ b/frontend/src/lib/components/dashboard/export/manifest/manifest-form.svelte @@ -233,8 +233,7 @@ scafReparInvoices = []; return; } - - console.log('Fetching assigned invoices for:', formData.manifest_number); + lastFetchAttempt = new Date().toLocaleTimeString(); invoicesLoading = true; const companyId = companyStore.activeCompany.id; @@ -251,11 +250,7 @@ allDebugInvoicesCount = allInvoices.length; // Mark all as selected for visual consistency (since they ARE linked) - allInvoices.forEach((inv) => (inv.is_selected = true)); - - console.log( - `Loaded ${allInvoices.length} export invoices for manifest ${formData.manifest_number}` - ); + allInvoices.forEach((inv) => (inv.is_selected = true)); // Helper to normalize system const getSystem = (s: string | undefined) => { @@ -297,13 +292,6 @@ isRepar(inv.invoice_type ?? undefined) ); - console.log('Invoices loaded:', { - total: allInvoices.length, - scaiiExp: scaiiExpInvoices.length, - scaiiRepar: scaiiReparInvoices.length, - scafExp: scafExpInvoices.length, - scafRepar: scafReparInvoices.length - }); } catch (e) { console.error('Error fetching invoices:', e); toast.error('Error al cargar facturas'); @@ -313,9 +301,7 @@ } $effect(() => { - console.log('Active tab changed:', activeTab); if (activeTab === 'facturas_expo') { - console.log('Triggering fetchInvoiceLists'); fetchInvoiceLists(); } }); @@ -612,38 +598,27 @@ ...scafReparInvoices ]; - const updatePromises = []; - - console.log('Starting batch update for invoices:', allTrackedInvoices.length); + const updatePromises = []; for (const inv of allTrackedInvoices) { const currentLink = inv.compliance_mx?.manifest_number; const shouldLink = inv.is_selected; - console.log( - `Invoice ${inv.invoice_number}: current=${currentLink}, selected=${shouldLink}, target=${formData.manifest_number}` - ); - // Case 1: Needs Linking (Selected but not currently linked to this manifest) - if (shouldLink && currentLink !== formData.manifest_number) { - console.log(`Linking invoice ${inv.id} to ${formData.manifest_number}`); + if (shouldLink && currentLink !== formData.manifest_number) { updatePromises.push( manifestApi.updateInvoiceCompliance(inv.id, companyId, formData.manifest_number) ); } // Case 2: Needs Unlinking (Not Selected but currently linked to this manifest) - else if (!shouldLink && currentLink === formData.manifest_number) { - console.log(`Unlinking invoice ${inv.id}`); + else if (!shouldLink && currentLink === formData.manifest_number) { updatePromises.push(manifestApi.updateInvoiceCompliance(inv.id, companyId, null)); } } - if (updatePromises.length > 0) { - console.log('Sending update promises:', updatePromises.length); + if (updatePromises.length > 0) { await Promise.all(updatePromises); - toast.success(`${updatePromises.length} facturas actualizadas`); - } else { - console.log('No invoices needed update'); + toast.success(`${updatePromises.length} facturas actualizadas`); } } @@ -1138,7 +1113,7 @@ (formData.vehicle_status = v)} > diff --git a/frontend/src/lib/components/dashboard/goods/modales/currency-selector-dialog.svelte b/frontend/src/lib/components/dashboard/goods/modales/currency-selector-dialog.svelte index d88cd5d9..4008778d 100644 --- a/frontend/src/lib/components/dashboard/goods/modales/currency-selector-dialog.svelte +++ b/frontend/src/lib/components/dashboard/goods/modales/currency-selector-dialog.svelte @@ -39,12 +39,10 @@ }); async function loadCurrencies() { - loading = true; - console.log("CurrencySelectorDialog: loading currencies (public)..."); + loading = true; try { // FIX: Usar API pública, sin company_id - const response = await currencyTypesApi.list(1, 100); - console.log("Respuesta Monedas Public FULL:", response); + const response = await currencyTypesApi.list(1, 100); if (response.error) { console.error("CurrencySelectorDialog Error:", response.error); @@ -54,8 +52,7 @@ if (response.data?.items) { items = response.data.items; - loaded = true; - console.log("CurrencySelectorDialog: loaded items", items.length); + loaded = true; } else { console.warn("No se encontraron monedas (public):", response); toast.error("No se encontraron monedas"); diff --git a/frontend/src/lib/components/dashboard/goods/parts/partForm.svelte b/frontend/src/lib/components/dashboard/goods/parts/partForm.svelte index f862a1f8..feb73f3e 100644 --- a/frontend/src/lib/components/dashboard/goods/parts/partForm.svelte +++ b/frontend/src/lib/components/dashboard/goods/parts/partForm.svelte @@ -251,22 +251,14 @@ delete commonData.sector; delete commonData.fraction_type; delete commonData.origin_country; - } - - console.log("Submitting Part Data:", { - isEdit, - partId, - commonData - }); + } if (isEdit && partId) { // TODO: Verify partId is number/string as expected - const res = await partsApi.update(Number(partId), commonData, activeCompanyId); - console.log("Update Response:", res); + const res = await partsApi.update(Number(partId), commonData, activeCompanyId); if (res.error) throw new Error(res.error); } else { - const result = await partsApi.create({ ...commonData, company_id: activeCompanyId }, activeCompanyId); - console.log("Create Response:", result); + const result = await partsApi.create({ ...commonData, company_id: activeCompanyId }, activeCompanyId); if (result.error) { error = result.error; return; } } toast.success(isEdit ? "Parte actualizada" : "Parte creada"); @@ -421,7 +413,7 @@
- + formData.weight_type = v}> {formData.weight_type} KG @@ -640,7 +632,7 @@
- + formData.weight_type = v}> {formData.weight_type} KG diff --git a/frontend/src/lib/components/dashboard/invoices/create-edit-dialog.svelte b/frontend/src/lib/components/dashboard/invoices/create-edit-dialog.svelte index c7037523..546ccfa4 100644 --- a/frontend/src/lib/components/dashboard/invoices/create-edit-dialog.svelte +++ b/frontend/src/lib/components/dashboard/invoices/create-edit-dialog.svelte @@ -42,8 +42,6 @@ path_pdf: "", path_xml: "", // Compliance MX fields - pedimento: "", - pedimento_code: "", remesa: null as number | null, aduana: "", customs_broker_id: "", @@ -64,7 +62,7 @@ freight: null as number | null, insurance: null as number | null, iva_mn: null as number | null, - iva_factor: null as number | null, + iva_factor: null as string | null, total_quantity: null as number | null, gross_weight: null as number | null, net_weight: null as number | null, @@ -95,15 +93,13 @@ cfdi_uuid: item.cfdi_uuid || "", path_pdf: item.path_pdf || "", path_xml: item.path_xml || "", - pedimento: item.compliance_mx?.pedimento || "", - pedimento_code: item.compliance_mx?.pedimento_code || "", remesa: item.compliance_mx?.remesa || null, aduana: item.compliance_mx?.aduana || "", - customs_broker_id: item.compliance_mx?.customs_broker_id || "", - provider_id: item.compliance_mx?.provider_id || "", - sold_to_id: item.compliance_mx?.sold_to_id || "", - shipped_to_id: item.compliance_mx?.shipped_to_id || "", - shipped_by_id: item.compliance_mx?.shipped_by_id || "", + customs_broker_id: item.compliance_mx?.customs_broker_id?.toString() || "", + provider_id: item.compliance_mx?.provider_id?.toString() || "", + sold_to_id: item.compliance_mx?.sold_to_id?.toString() || "", + shipped_to_id: item.compliance_mx?.shipped_to_id?.toString() || "", + shipped_by_id: item.compliance_mx?.shipped_by_id?.toString() || "", is_mixed: item.compliance_mx?.is_mixed || false, waste_type: item.compliance_mx?.waste_type || "", appendix_17: item.compliance_mx?.appendix_17 || null, @@ -145,8 +141,6 @@ cfdi_uuid: "", path_pdf: "", path_xml: "", - pedimento: "", - pedimento_code: "", remesa: null, aduana: "", customs_broker_id: "", @@ -198,6 +192,7 @@ let response; if (isEditing && item) { const payload: UpdateInvoiceData = { + id: item.id, operation_type: formData.operation_type, invoice_type: formData.invoice_type || null, invoice_number: formData.invoice_number || null, @@ -213,18 +208,16 @@ path_pdf: formData.path_pdf || null, path_xml: formData.path_xml || null, compliance_mx: { - pedimento: formData.pedimento || null, - pedimento_code: formData.pedimento_code || null, remesa: formData.remesa, aduana: formData.aduana || null, - customs_broker_id: formData.customs_broker_id || null, - provider_id: formData.provider_id || null, - sold_to_id: formData.sold_to_id || null, - shipped_to_id: formData.shipped_to_id || null, - shipped_by_id: formData.shipped_by_id || null, + customs_broker_id: formData.customs_broker_id ? parseInt(formData.customs_broker_id) : null, + provider_id: formData.provider_id ? parseInt(formData.provider_id) : null, + sold_to_id: formData.sold_to_id ? parseInt(formData.sold_to_id) : null, + shipped_to_id: formData.shipped_to_id ? parseInt(formData.shipped_to_id) : null, + shipped_by_id: formData.shipped_by_id ? parseInt(formData.shipped_by_id) : null, is_mixed: formData.is_mixed, waste_type: formData.waste_type || null, - appendix_17: formData.appendix_17, + appendix_17: formData.appendix_17 || null, edocument: formData.edocument || null }, financials: { @@ -245,10 +238,12 @@ }; response = await invoicesApi.update(item.id, companyStore.activeCompany.id, payload); } else { - const payload: CreateInvoiceData = { + const payload: CreateInvoiceData = { + system: "a76", + document_type: "invoice", operation_type: formData.operation_type, - invoice_type: formData.invoice_type || null, - invoice_number: formData.invoice_number || null, + invoice_type: formData.invoice_type, + invoice_number: formData.invoice_number, project_number: formData.project_number || null, purchase_order: formData.purchase_order || null, related_doc_id: formData.related_doc_id, @@ -261,18 +256,16 @@ path_pdf: formData.path_pdf || null, path_xml: formData.path_xml || null, compliance_mx: { - pedimento: formData.pedimento || null, - pedimento_code: formData.pedimento_code || null, remesa: formData.remesa, aduana: formData.aduana || null, - customs_broker_id: formData.customs_broker_id || null, - provider_id: formData.provider_id || null, - sold_to_id: formData.sold_to_id || null, - shipped_to_id: formData.shipped_to_id || null, - shipped_by_id: formData.shipped_by_id || null, + customs_broker_id: formData.customs_broker_id ? parseInt(formData.customs_broker_id) : null, + provider_id: formData.provider_id ? parseInt(formData.provider_id) : null, + sold_to_id: formData.sold_to_id ? parseInt(formData.sold_to_id) : null, + shipped_to_id: formData.shipped_to_id ? parseInt(formData.shipped_to_id) : null, + shipped_by_id: formData.shipped_by_id ? parseInt(formData.shipped_by_id) : null, is_mixed: formData.is_mixed, waste_type: formData.waste_type || null, - appendix_17: formData.appendix_17, + appendix_17: formData.appendix_17 || null, edocument: formData.edocument || null }, financials: { @@ -307,8 +300,7 @@ : JSON.stringify(response.error); if (errorStr.includes('No existe un Tipo de Cambio registrado') || errorStr.includes('financials.exchange_rate')) { - // Interceptar error de tipo de cambio - console.log("Interceptor: Exchange rate missing error caught (Invoice)."); + // Interceptar error de tipo de cambio error = null; const dateMatch = errorStr.match(/(\d{4}-\d{2}-\d{2})/); @@ -510,24 +502,6 @@
-
- - -
- -
- - -
-
{ - console.log('OthersTabForm props:', { - invoiceType, - operationType, - isMixed: formData.is_mixed, - rule: formData.rule_3121_parties_ii - }); - }); {#if invoiceType !== 'MEX'} diff --git a/frontend/src/routes/dashboard/admin/roles/+page.svelte b/frontend/src/routes/dashboard/admin/roles/+page.svelte index c2ea9f15..60213ec7 100644 --- a/frontend/src/routes/dashboard/admin/roles/+page.svelte +++ b/frontend/src/routes/dashboard/admin/roles/+page.svelte @@ -85,8 +85,6 @@ try { const response = await permissionsAPI.list(); allPermissions = response.items || []; - console.log('Total permissions loaded:', allPermissions.length); - console.log('Unique permission IDs:', new Set(allPermissions.map(p => p.id)).size); if (selectedRole) { updateAvailablePermissions(); } @@ -118,17 +116,12 @@ const assignedIds = rolePermissions.map((rp) => rp.permission_id); availablePermissions = allPermissions.filter((p) => !assignedIds.includes(p.id)); - console.log('Available permissions:', availablePermissions.length); - console.log('Unique available IDs:', new Set(availablePermissions.map(p => p.id)).size); - updatePermissionsByModule(); } function updatePermissionsByModule() { const grouped = new Map(); - console.log('Grouping permissions:', availablePermissions.length); - // Filtrar por búsqueda const filtered = availablePermissions.filter((p) => { if (!permissionSearchQuery.trim()) return true; @@ -147,8 +140,6 @@ grouped.get(p.module)!.push(p); }); - console.log('Grouped by module:', Array.from(grouped.entries()).map(([k, v]) => `${k}: ${v.length}`)); - permissionsByModule = grouped; } diff --git a/frontend/src/routes/dashboard/general_catalogs/doda/edit/[[id]]/+page.svelte b/frontend/src/routes/dashboard/general_catalogs/doda/edit/[[id]]/+page.svelte index 45d9eb20..67e241a0 100644 --- a/frontend/src/routes/dashboard/general_catalogs/doda/edit/[[id]]/+page.svelte +++ b/frontend/src/routes/dashboard/general_catalogs/doda/edit/[[id]]/+page.svelte @@ -115,13 +115,10 @@ const currentId = $page.params.id; const companyId = companyStore.activeCompany?.id; - console.log('DEBUG: Effect triggered', { currentId, companyId }); if (currentId && companyId) { - console.log('DEBUG: Calling loadDoda with', currentId); loadDoda(Number(currentId)); } else if (!currentId) { - console.log('DEBUG: No ID, resetting form'); formData = getEmptyForm(); error = null; } @@ -131,15 +128,8 @@ loading = true; try { const companyId = companyStore.activeCompany?.id; - console.log('DEBUG: loadDoda executing', { dodaId, companyId }); - - if (!companyId) { - console.error('DEBUG: No company ID available in loadDoda'); - return; - } const data = await getDoda(dodaId, companyId); - console.log('DEBUG: getDoda response', data); if (data) { formData = { diff --git a/frontend/src/routes/dashboard/invoices/edit/[id]/+page.svelte b/frontend/src/routes/dashboard/invoices/edit/[id]/+page.svelte index 97ea106a..4b41e85f 100644 --- a/frontend/src/routes/dashboard/invoices/edit/[id]/+page.svelte +++ b/frontend/src/routes/dashboard/invoices/edit/[id]/+page.svelte @@ -183,6 +183,7 @@ cantidad_guias_embarque: null, destino_origen: '', puerto_entrada: '', + vehicle_data: '', fue_revisado_equipo: false, sub_division: false, funge_como_cd: false, @@ -191,7 +192,16 @@ semaforo_verde_aduana_mexicana: false, semaforo_verde_aduana_americana: false, semaforo_rojo_aduana_mexicana: false, - semaforo_rojo_aduana_americana: false + semaforo_rojo_aduana_americana: false, + // Export fields + is_mixed: false, + reason_export: '1', + purchase_order: '', + payment_terms: '', + handling_fees: 0, + cfdi_uuid: '', + path_pdf: '', + path_xml: '' }; function ensureItemsFormData(initial?: any) { diff --git a/frontend/src/routes/dashboard/pedimentos/+page.svelte b/frontend/src/routes/dashboard/pedimentos/+page.svelte index 9da04bbe..dd9613e9 100644 --- a/frontend/src/routes/dashboard/pedimentos/+page.svelte +++ b/frontend/src/routes/dashboard/pedimentos/+page.svelte @@ -85,15 +85,7 @@ function handleRowClick(pedimento: Pedimento) { // Toggle: si ya está seleccionado, deseleccionar; si no, seleccionar - selectedId = selectedId === pedimento.id ? null : pedimento.id; - console.log( - '🔘 Row clicked, pedimento.id:', - pedimento.id, - 'selectedId:', - selectedId, - 'hasSelection:', - hasSelection - ); + selectedId = selectedId === pedimento.id ? null : pedimento.id; } function handleEditSelected() {