From 4f31736a403783ba7c5abe1a17cd3667bd724216 Mon Sep 17 00:00:00 2001 From: hreyes Date: Tue, 28 Apr 2026 07:24:52 -0600 Subject: [PATCH 1/2] feature/errores-legibles-tabla --- .../items/exports/validators/calculations.py | 43 +++++++++++++------ .../a76/items/exports/validators/update.py | 1 + .../items/imports/validators/calculations.py | 39 +++++++++++------ .../a76/items/imports/validators/update.py | 1 + 4 files changed, 56 insertions(+), 28 deletions(-) diff --git a/backend/api/v1/modules/a76/items/exports/validators/calculations.py b/backend/api/v1/modules/a76/items/exports/validators/calculations.py index d5703cd4..f49a195e 100644 --- a/backend/api/v1/modules/a76/items/exports/validators/calculations.py +++ b/backend/api/v1/modules/a76/items/exports/validators/calculations.py @@ -239,27 +239,42 @@ def calculate_values( if not result: return + if not line.financial or not line.quantity: + return + currency, currency_type, exchange_rate = result if currency_type in ("USD", "ME"): currency = "foreign" elif currency_type in ("MXN", "MN"): currency = "local" + # Evitar None * None / NoneType * Decimal al guardar sin cantidad o sin costo capturado + qty = ( + line.quantity.quantity + if line.quantity.quantity is not None + else Decimal("0") + ) + capture = ( + line.financial.unit_cost_capture + if line.financial.unit_cost_capture is not None + else Decimal("0") + ) + if currency == "foreign": # ME - line.financial.unit_cost_usd = line.financial.unit_cost_capture - line.financial.value_usd = line.financial.unit_cost_usd * line.quantity.quantity - line.financial.unit_cost_mxn = line.financial.unit_cost_capture * (exchange_rate or 1) - line.financial.value_mxn = line.financial.unit_cost_mxn * line.quantity.quantity - line.financial.value_mc = line.financial.unit_cost_usd * line.quantity.quantity + line.financial.unit_cost_usd = capture + line.financial.value_usd = capture * qty + line.financial.unit_cost_mxn = capture * (exchange_rate or 1) + line.financial.value_mxn = line.financial.unit_cost_mxn * qty + line.financial.value_mc = capture * qty elif currency == "local": # MN - line.financial.unit_cost_mxn = line.financial.unit_cost_capture - line.financial.value_mxn = line.financial.unit_cost_mxn * line.quantity.quantity - line.financial.unit_cost_usd = line.financial.unit_cost_capture / (exchange_rate or 1) - line.financial.value_usd = line.financial.unit_cost_usd * line.quantity.quantity - line.financial.value_mc = line.financial.unit_cost_usd * line.quantity.quantity + line.financial.unit_cost_mxn = capture + line.financial.value_mxn = line.financial.unit_cost_mxn * qty + line.financial.unit_cost_usd = capture / (exchange_rate or 1) + line.financial.value_usd = line.financial.unit_cost_usd * qty + line.financial.value_mc = line.financial.unit_cost_usd * qty elif currency == "manual": # MC - line.financial.unit_cost_usd = line.financial.unit_cost_capture / (exchange_rate or 1) - line.financial.value_usd = line.financial.unit_cost_usd * line.quantity.quantity + line.financial.unit_cost_usd = capture / (exchange_rate or 1) + line.financial.value_usd = line.financial.unit_cost_usd * qty line.financial.unit_cost_mxn = line.financial.unit_cost_usd * (exchange_rate or 1) - line.financial.value_mxn = line.financial.unit_cost_mxn * line.quantity.quantity - line.financial.value_mc = line.financial.unit_cost_capture * line.quantity.quantity + line.financial.value_mxn = line.financial.unit_cost_mxn * qty + line.financial.value_mc = capture * qty diff --git a/backend/api/v1/modules/a76/items/exports/validators/update.py b/backend/api/v1/modules/a76/items/exports/validators/update.py index 2d3e13e9..896f8240 100644 --- a/backend/api/v1/modules/a76/items/exports/validators/update.py +++ b/backend/api/v1/modules/a76/items/exports/validators/update.py @@ -98,6 +98,7 @@ def validate_update( line.financial.unit_cost_mxn = unit_cost_capture quantity = line.quantity.quantity if line.quantity.quantity is not None else existing_line.quantity.quantity + quantity = quantity if quantity is not None else Decimal("0") if line.financial.unit_cost_usd is not None: line.financial.value_usd = line.financial.unit_cost_usd * quantity diff --git a/backend/api/v1/modules/a76/items/imports/validators/calculations.py b/backend/api/v1/modules/a76/items/imports/validators/calculations.py index 8e80ba8c..be6754a0 100644 --- a/backend/api/v1/modules/a76/items/imports/validators/calculations.py +++ b/backend/api/v1/modules/a76/items/imports/validators/calculations.py @@ -138,21 +138,32 @@ def calculate_values( currency = "local" # si currency_type es otro o None, se usa currency tal cual + qty = ( + line.quantity.quantity + if line.quantity.quantity is not None + else Decimal("0") + ) + capture = ( + line.financial.unit_cost_capture + if line.financial.unit_cost_capture is not None + else Decimal("0") + ) + if currency == "foreign": - line.financial.unit_cost_usd = line.financial.unit_cost_capture - line.financial.value_usd = line.financial.unit_cost_usd * line.quantity.quantity - line.financial.unit_cost_mxn = line.financial.unit_cost_capture * (exchange_rate or 1) - line.financial.value_mxn = line.financial.unit_cost_mxn * line.quantity.quantity - line.financial.value_mc = line.financial.unit_cost_usd * line.quantity.quantity + line.financial.unit_cost_usd = capture + line.financial.value_usd = capture * qty + line.financial.unit_cost_mxn = capture * (exchange_rate or 1) + line.financial.value_mxn = line.financial.unit_cost_mxn * qty + line.financial.value_mc = capture * qty elif currency == "local": - line.financial.unit_cost_mxn = line.financial.unit_cost_capture - line.financial.value_mxn = line.financial.unit_cost_mxn * line.quantity.quantity - line.financial.unit_cost_usd = line.financial.unit_cost_capture / (exchange_rate or 1) - line.financial.value_usd = line.financial.unit_cost_usd * line.quantity.quantity - line.financial.value_mc = line.financial.unit_cost_usd * line.quantity.quantity + line.financial.unit_cost_mxn = capture + line.financial.value_mxn = line.financial.unit_cost_mxn * qty + line.financial.unit_cost_usd = capture / (exchange_rate or 1) + line.financial.value_usd = line.financial.unit_cost_usd * qty + line.financial.value_mc = line.financial.unit_cost_usd * qty elif currency == "manual": - line.financial.unit_cost_usd = line.financial.unit_cost_capture / (exchange_rate or 1) - line.financial.value_usd = line.financial.unit_cost_usd * line.quantity.quantity + line.financial.unit_cost_usd = capture / (exchange_rate or 1) + line.financial.value_usd = line.financial.unit_cost_usd * qty line.financial.unit_cost_mxn = line.financial.unit_cost_usd * (exchange_rate or 1) - line.financial.value_mxn = line.financial.unit_cost_mxn * line.quantity.quantity - line.financial.value_mc = line.financial.unit_cost_capture * line.quantity.quantity \ No newline at end of file + line.financial.value_mxn = line.financial.unit_cost_mxn * qty + line.financial.value_mc = capture * qty \ No newline at end of file diff --git a/backend/api/v1/modules/a76/items/imports/validators/update.py b/backend/api/v1/modules/a76/items/imports/validators/update.py index 3f891e0a..ba69b5b4 100644 --- a/backend/api/v1/modules/a76/items/imports/validators/update.py +++ b/backend/api/v1/modules/a76/items/imports/validators/update.py @@ -95,6 +95,7 @@ def validate_update( line.financial.unit_cost_mxn = unit_cost_capture quantity = line.quantity.quantity if line.quantity.quantity is not None else existing_line.quantity.quantity + quantity = quantity if quantity is not None else Decimal("0") if line.financial.unit_cost_usd is not None: line.financial.value_usd = line.financial.unit_cost_usd * quantity From 9ca3aabd7a0f6aeb0803fb306758f85f4ca9d57a Mon Sep 17 00:00:00 2001 From: hreyes Date: Tue, 28 Apr 2026 07:34:34 -0600 Subject: [PATCH 2/2] feature/errores-legibles-tabla --- frontend/messages/en.json | 13 +- frontend/messages/es.json | 13 +- frontend/src/lib/actions/portal.ts | 33 +++ .../edit/items/fa/class-dialog.svelte | 23 +- .../edit/items/fa/item-configuration.svelte | 46 ++-- .../edit/items/fa/item-sheet-fa.svelte | 49 ++++- .../invoices/edit/items/fa/main-data.svelte | 124 ++++++----- .../edit/items/fa/packages-section.svelte | 23 +- .../edit/items/fa/part-number-dialog.svelte | 23 +- .../invoices/edit/items/fa/tab-series.svelte | 22 +- .../edit/items/focus-item-sheet-field.ts | 75 +++++++ .../edit/items/inv/item-sheet-inv.svelte | 31 ++- .../invoices/edit/items/items-tab-form.svelte | 145 +++++++++---- .../alert-dialog/alert-dialog-content.svelte | 3 + .../ui/dialog/dialog-content.svelte | 3 + .../components/ui/error-panel-notice.svelte | 203 ++++++++++++++++++ .../ui/floating-inline-notice.svelte | 73 +++++++ .../components/ui/sheet/sheet-content.svelte | 3 + frontend/src/lib/utils/items-logic.ts | 106 +++++++++ .../utils/partida-notice-interact-outside.ts | 17 ++ 20 files changed, 878 insertions(+), 150 deletions(-) create mode 100644 frontend/src/lib/actions/portal.ts create mode 100644 frontend/src/lib/components/dashboard/invoices/edit/items/focus-item-sheet-field.ts create mode 100644 frontend/src/lib/components/ui/error-panel-notice.svelte create mode 100644 frontend/src/lib/components/ui/floating-inline-notice.svelte create mode 100644 frontend/src/lib/utils/partida-notice-interact-outside.ts diff --git a/frontend/messages/en.json b/frontend/messages/en.json index 095efa87..3b1e30d2 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -1193,7 +1193,18 @@ "dollars": "Dollars:", "pesos": "Pesos:", "capture_value": "Capture Value:", - "customs_value_short": "Customs:" + "customs_value_short": "Customs:", + "error_panel_title_with_count": "Errors ({count})", + "warning_panel_title": "Warning", + "error_panel_fallback_message": "We couldn't save your changes. Review the information and try again.", + "error_panel_clear": "Clear", + "error_panel_column_type": "Type", + "error_panel_column_field": "Field", + "error_panel_column_message": "Message", + "error_panel_empty_field": "—", + "error_panel_dismiss_row_aria": "Dismiss this error", + "error_panel_toggle_details_aria": "Show or hide error details", + "inline_notice_close_aria": "Dismiss notice" } }, "invoice_item_fa": { diff --git a/frontend/messages/es.json b/frontend/messages/es.json index 06351ad7..6ecb0021 100644 --- a/frontend/messages/es.json +++ b/frontend/messages/es.json @@ -1192,7 +1192,18 @@ "dollars": "Dólares:", "pesos": "Pesos:", "capture_value": "De Captura:", - "customs_value_short": "Aduana:" + "customs_value_short": "Aduana:", + "error_panel_title_with_count": "Errores ({count})", + "warning_panel_title": "Advertencia", + "error_panel_fallback_message": "No pudimos guardar los cambios. Revisa la información e intenta de nuevo.", + "error_panel_clear": "Limpiar", + "error_panel_column_type": "Tipo", + "error_panel_column_field": "Campo", + "error_panel_column_message": "Mensaje", + "error_panel_empty_field": "—", + "error_panel_dismiss_row_aria": "Quitar este error", + "error_panel_toggle_details_aria": "Mostrar u ocultar el detalle de errores", + "inline_notice_close_aria": "Cerrar aviso" } }, "invoice_item_fa": { diff --git a/frontend/src/lib/actions/portal.ts b/frontend/src/lib/actions/portal.ts new file mode 100644 index 00000000..94f267df --- /dev/null +++ b/frontend/src/lib/actions/portal.ts @@ -0,0 +1,33 @@ +/** + * Svelte action that teleports a DOM node to a target element outside the + * current component tree. This ensures the node is not affected by focus + * traps, overlays, or event interceptors (e.g. Radix DismissibleLayer) that + * are scoped to a parent Dialog/Sheet portal. + * + * Usage: + *
...
→ appended to + *
...
→ appended to #target + */ +export function portal(node: HTMLElement, target: HTMLElement | string = 'body') { + function mount() { + const targetEl = + typeof target === 'string' + ? (document.querySelector(target) as HTMLElement | null) + : target; + + if (!targetEl) return; + targetEl.appendChild(node); + } + + mount(); + + return { + update(newTarget: HTMLElement | string) { + target = newTarget; + mount(); + }, + destroy() { + node.remove(); + } + }; +} diff --git a/frontend/src/lib/components/dashboard/invoices/edit/items/fa/class-dialog.svelte b/frontend/src/lib/components/dashboard/invoices/edit/items/fa/class-dialog.svelte index 3d091ec5..6636c078 100644 --- a/frontend/src/lib/components/dashboard/invoices/edit/items/fa/class-dialog.svelte +++ b/frontend/src/lib/components/dashboard/invoices/edit/items/fa/class-dialog.svelte @@ -3,9 +3,10 @@ import * as Table from '$lib/components/ui/table'; import { Input } from '$lib/components/ui/input'; import { Button } from '$lib/components/ui/button'; - import { Search, Loader2, Info } from 'lucide-svelte'; - import { toast } from 'svelte-sonner'; + import { Search, Loader2, Info, AlertCircle } from 'lucide-svelte'; import { companyStore } from '$lib/stores/company.svelte'; + + let classesLoadError = $state(''); import { onMount } from 'svelte'; import { classesApi } from '$lib/api/dashboard/a76/classes'; @@ -57,7 +58,7 @@ currentPage = page; } catch (error) { console.error('Error fetching classes:', error); - toast.error('Error al cargar clases'); + classesLoadError = 'No se pudieron cargar las clases. Intenta de nuevo.'; if (page === 1) { classes = []; totalItems = 0; @@ -133,6 +134,22 @@ + {#if classesLoadError} + + {/if} +
diff --git a/frontend/src/lib/components/dashboard/invoices/edit/items/fa/item-configuration.svelte b/frontend/src/lib/components/dashboard/invoices/edit/items/fa/item-configuration.svelte index 5f36bb66..5c00deac 100644 --- a/frontend/src/lib/components/dashboard/invoices/edit/items/fa/item-configuration.svelte +++ b/frontend/src/lib/components/dashboard/invoices/edit/items/fa/item-configuration.svelte @@ -115,16 +115,16 @@ {m['invoice_item_fa.configuration.main_item_number']()} - setSubitemNumber(e.currentTarget.valueAsNumber || 0)} - class="h-7 text-xs" - - placeholder={m['invoice_item_fa.configuration.main_item_number_placeholder']()} - /> + setSubitemNumber(e.currentTarget.valueAsNumber || 0)} + class="h-7 text-xs" + placeholder={m['invoice_item_fa.configuration.main_item_number_placeholder']()} + data-item-validation-path="fa_data.subitem_number" + /> {/if}
@@ -167,23 +167,25 @@ - +
- +
diff --git a/frontend/src/lib/components/dashboard/invoices/edit/items/fa/item-sheet-fa.svelte b/frontend/src/lib/components/dashboard/invoices/edit/items/fa/item-sheet-fa.svelte index 4b928c81..f8c548e7 100644 --- a/frontend/src/lib/components/dashboard/invoices/edit/items/fa/item-sheet-fa.svelte +++ b/frontend/src/lib/components/dashboard/invoices/edit/items/fa/item-sheet-fa.svelte @@ -10,7 +10,7 @@ import { Label } from '$lib/components/ui/label'; import { RadioGroup, RadioGroupItem } from '$lib/components/ui/radio-group'; import { Separator } from '$lib/components/ui/separator'; - import { Loader2, Package, Save, X, FileText, Folder, Calendar } from 'lucide-svelte'; + import { Loader2, Package, Save, X, FileText, Folder, Calendar, AlertCircle } from 'lucide-svelte'; import type { Invoice } from '$lib/api/dashboard/a76/invoices'; import { invoicesApi } from '$lib/api/dashboard/a76/invoices'; import { itemsApi, type Item, type ImportLineWithBalance } from '$lib/api/dashboard/a76/items'; @@ -41,7 +41,11 @@ onSave, onCancel, isTargetingPreset = false, - isSaving = false + isSaving = false, + saveError = null, + onDismissSaveError, + activeTab = $bindable('generales'), + onValidationFieldChange }: { open: boolean; isEditMode?: boolean; @@ -53,6 +57,10 @@ onCancel?: () => void; isTargetingPreset?: boolean; isSaving?: boolean; + saveError?: { field: string; message: string }[] | null; + onDismissSaveError?: () => void; + activeTab?: string; + onValidationFieldChange?: (fieldPath: string) => void; } = $props(); // Acceso directo a la primera línea para evitar repeticiones en el HTML @@ -273,7 +281,6 @@ { value: 'identificadores', label: m['invoice_item_fa.item_sheet.tab_identifiers'](), visible: visibility.showIdentifiersTab } ].filter((tab) => tab.visible)); const tabListStyle = $derived(`grid-template-columns: repeat(${visibleTabs.length || 1}, minmax(0, 1fr));`); - let activeTab = $state('generales'); const tabMapping: Record = { tab1: 'generales', tab2: 'continuacion', @@ -354,7 +361,17 @@ -
+
{ + const path = (e.target as HTMLElement).getAttribute('data-item-validation-path'); + if (path) onValidationFieldChange?.(path); + }} + onchange={(e) => { + const path = (e.target as HTMLElement).getAttribute('data-item-validation-path'); + if (path) onValidationFieldChange?.(path); + }} + >
{#if editingItem} @@ -726,9 +743,29 @@